_fixup
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user