This commit is contained in:
2025-07-03 19:32:36 +03:00
parent 71755bcee8
commit 2868ebac0f
4 changed files with 133 additions and 0 deletions

View File

@@ -165,6 +165,78 @@ bool LinuxFileSystem::ShowFileExplorer(const StringView& path)
return false;
}
bool LinuxFileSystem::CopyFile(const StringView& dst, const StringView& src)
{
const StringAsUTF8<> srcANSI(*src, src.Length());
const StringAsUTF8<> dstANSI(*dst, dst.Length());
int srcFile, dstFile;
char buffer[4096];
ssize_t readSize;
int cachedError;
srcFile = open(srcANSI.Get(), O_RDONLY);
if (srcFile < 0)
return true;
dstFile = open(dstANSI.Get(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (dstFile < 0)
goto out_error;
// first try the kernel method
struct stat statBuf;
fstat(srcFile, &statBuf);
readSize = 1;
while (readSize > 0)
{
readSize = sendfile(dstFile, srcFile, 0, statBuf.st_size);
}
// sendfile could fail for example if the input file is not nmap'able
// in this case we fall back to the read/write loop
if (readSize < 0)
{
while (readSize = read(srcFile, buffer, sizeof(buffer)), readSize > 0)
{
char* ptr = buffer;
ssize_t writeSize;
do
{
writeSize = write(dstFile, ptr, readSize);
if (writeSize >= 0)
{
readSize -= writeSize;
ptr += writeSize;
}
else if (errno != EINTR)
{
goto out_error;
}
} while (readSize > 0);
}
}
if (readSize == 0)
{
if (close(dstFile) < 0)
{
dstFile = -1;
goto out_error;
}
close(srcFile);
// Success
return false;
}
out_error:
cachedError = errno;
close(srcFile);
if (dstFile >= 0)
close(dstFile);
errno = cachedError;
return true;
}
bool LinuxFileSystem::MoveFileToRecycleBin(const StringView& path)
{
String trashDir;