From 8af3a15baecdf1fee8da4700c2444b22bec6a679 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Mon, 27 Jan 2014 11:58:49 +0100 Subject: [PATCH] CFileHelpers::copyFile: remove duplicated code there is no reason I can imagine to distinguish between large and small files Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/2c5e5c8a3f9417f59761883836b34c2402e221c0 Author: Stefan Seyfried Date: 2014-01-27 (Mon, 27 Jan 2014) --- src/system/helpers.cpp | 53 ++++++++++++------------------------------ 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 5f9373bbc..99c37c012 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -419,45 +419,22 @@ bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t mode) uint32_t block; off64_t fsizeSrc64 = lseek64(fd1, 0, SEEK_END); lseek64(fd1, 0, SEEK_SET); - if (fsizeSrc64 > 0x7FFFFFF0) { // > 2GB - off64_t fsize64 = fsizeSrc64; - block = FileBufSize; - //printf("#####[%s] fsizeSrc64: %lld 0x%010llX - large file\n", __FUNCTION__, fsizeSrc64, fsizeSrc64); - while(fsize64 > 0) { - if(fsize64 < (off64_t)FileBufSize) - block = (uint32_t)fsize64; - read(fd1, FileBuf, block); - write(fd2, FileBuf, block); - fsize64 -= block; - } - lseek64(fd2, 0, SEEK_SET); - off64_t fsizeDst64 = lseek64(fd2, 0, SEEK_END); - if (fsizeSrc64 != fsizeDst64){ - close(fd1); - close(fd2); - return false; - } + off64_t fsize64 = fsizeSrc64; + block = FileBufSize; + //printf("#####[%s] fsizeSrc64: %lld 0x%010llX - large file\n", __func__, fsizeSrc64, fsizeSrc64); + while (fsize64 > 0) { + if (fsize64 < (off64_t)FileBufSize) + block = (uint32_t)fsize64; + read(fd1, FileBuf, block); /* FIXME: short read??? */ + write(fd2, FileBuf, block); /* FIXME: short write?? */ + fsize64 -= block; } - else { // < 2GB - off_t fsizeSrc = lseek(fd1, 0, SEEK_END); - lseek(fd1, 0, SEEK_SET); - off_t fsize = fsizeSrc; - block = FileBufSize; - //printf("#####[%s] fsizeSrc: %ld 0x%08lX - normal file\n", __FUNCTION__, fsizeSrc, fsizeSrc); - while(fsize > 0) { - if(fsize < (off_t)FileBufSize) - block = (uint32_t)fsize; - read(fd1, FileBuf, block); - write(fd2, FileBuf, block); - fsize -= block; - } - lseek(fd2, 0, SEEK_SET); - off_t fsizeDst = lseek(fd2, 0, SEEK_END); - if (fsizeSrc != fsizeDst){ - close(fd1); - close(fd2); - return false; - } + lseek64(fd2, 0, SEEK_SET); + off64_t fsizeDst64 = lseek64(fd2, 0, SEEK_END); + if (fsizeSrc64 != fsizeDst64) { + close(fd1); + close(fd2); + return false; } close(fd1); close(fd2);