properties = &info;
else {
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_1,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_COPY_FILE_1,
i18n("could not find: $ (errno: $2)")).arg(source)
.arg(errno).end();
}
FILE* fpSource = fopen(source, "rb");
if (fpSource == NULL){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_2,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_COPY_FILE_2,
i18n("cannot open $1 (errno: $2)"))
.arg(source).arg(errno).end();
} else {
FILE* fpTarget = fopen(target, "w");
if (fpTarget == NULL){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_3,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_COPY_FILE_3,
i18n("cannot open $1 (errno: $2)"))
.arg(target).arg(errno).end();
} else{
blockSize = size;
if (fread(buffer.buffer(), blockSize, 1, fpSource) != 1){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_5,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_COPY_FILE_5,
i18n("cannot read $1 (errno: $2)"))
.arg(source).arg(errno).end();
break;
if ((written = fwrite(buffer.buffer(), 1, blockSize,
fpTarget)) != blockSize){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_6,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_COPY_FILE_6,
i18n("cannot write $1 [$2] (errno: $3)"))
.arg(target).arg(written).arg(errno).end();
break;
times.modtime = properties->st_mtime;
if (utime(fullName, ×) != 0){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_SET_PROPERTIES_1,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_SET_PROPERTIES_1,
i18n("cannot change file times: $1 (errno: $2)"))
.arg(fullName).arg(errno).end();
rc = false;
}
- if (chmod(fullName, properties->st_mode) != 0) {
+ int rights = properties->st_mode & (S_IRWXO | S_IRWXG | S_IRWXU);
+ if (chmod(fullName, rights) != 0) {
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_SET_PROPERTIES_2,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_SET_PROPERTIES_2,
i18n("cannot change file modes: $1 (errno: $2)"))
.arg(fullName).arg(errno).end();
rc = false;
}
if (chown(fullName, properties->st_uid, properties->st_gid) != 0){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_SET_PROPERTIES_3,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_SET_PROPERTIES_3,
i18n("cannot change file owner: $1 (errno: $2)"))
.arg(fullName).arg(errno).end();
rc = false;
// no, then we make it:
if (_mkdir(path.str(), ALLPERMS) != 0){
if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_MAKE_DIR_1,
+ logger->sayF(LOG_ERROR | CAT_FILE, LC_MAKE_DIR_1,
i18n("could not make directory $1 (errno: $2)"))
.arg(path.str()).arg(errno).end();
rc = false;
setFilterFromProgramArgs(filter);
int64_t sumSizes = 0;
int files = 0;
- int dirs = 0;
- ReByteBuffer source;
- ReByteBuffer targetFile;
+ int treeFiles = 0;
+ int treeDirs = 0;
+ int64_t treeSumSizes = 0ll;
+ ReByteBuffer source, targetFile;
for (int ix = 0; ix < m_programArgs.getArgCount() - 1; ix++){
source.set(m_programArgs.getArg(ix), -1);
target.setLength(lengthTargetBase);
ReDirStatus_t* entry;
ReByteBuffer line;
while( (entry = traverser.nextFile(level, &filter)) != NULL){
+ if (entry->isDirectory())
+ continue;
// append the new relative path from source to target:
target.setLength(ixTargetRelative);
- const char* targetRelativePath = target.str() + ixTargetRelative;
target.append(entry->m_path.str() + ixSourceRelative, -1);
if (stat(target.str(), &info) != 0)
makeDirWithParents(target, ixTargetRelative, traverser);
targetFile.set(target).append(entry->node(), -1);
+ const char* targetRelativePath = targetFile.str() + ixTargetRelative + 1;
bool exists = stat(targetFile.str(), &info) == 0;
- if (! exists && ! mustExist){
+ if (! exists && mustExist){
if (chatterMode)
fprintf(m_output, "-ignored: %s does not exist\n", targetRelativePath);
continue;
}
- if (exists && addOnly){
- if (chatterMode)
- fprintf(m_output, "~ignored: %s exists\n", targetRelativePath);
- continue;
- }
- if (ignoreDate && entry->fileSize() == info.st_size){
- if (chatterMode)
- fprintf(m_output, "_ignored: %s same size\n", targetRelativePath);
- continue;
- }
- if (! ignoreDate && entry->filetimeToTime(entry->modified()) - info.st_mtime
- > maxFileTimeDiff) {
- if (chatterMode)
- fprintf(m_output, "=ignored: %s same time\n", targetRelativePath);
- continue;
- } else {
- if (entry->isDirectory())
- dirs++;
- else{
- files++;
- sumSizes += entry->fileSize();
+ if (exists){
+ if (addOnly){
+ if (chatterMode)
+ fprintf(m_output, "~ignored: %s exists\n", targetRelativePath);
+ continue;
+ }
+ if (ignoreDate && entry->fileSize() == info.st_size){
+ if (chatterMode)
+ fprintf(m_output, "_ignored: %s same size\n", targetRelativePath);
+ continue;
+ }
+ // target younger than source?
+ if (! ignoreDate && info.st_mtime - entry->filetimeToTime(entry->modified())
+ > maxFileTimeDiff) {
+ if (chatterMode)
+ fprintf(m_output, "=ignored: %s same time\n", targetRelativePath);
+ continue;
}
- if (verbose || chatterMode || dry)
- fprintf(m_output, "%c%s%s\n", exists ? '!' : '+', targetRelativePath,
- dry ? " would be copied" : "");
- if (! dry)
- copyFile(entry, target.str());
}
+ files++;
+ sumSizes += entry->fileSize();
+ if (verbose || chatterMode)
+ fprintf(m_output, "%c%s%s\n", exists ? '!' : '+', targetRelativePath,
+ dry ? " would be copied" : "");
+ if (! dry)
+ copyFile(entry, targetFile.str());
}
+ treeFiles += traverser.files();
+ treeDirs += traverser.directories();
+ treeSumSizes+= traverser.sizes();
}
if (verbose){
int duration = int(time(NULL) - start);
- fprintf(m_output, "=== %d dir(s) and %d file(s) with %.6f MByte in %02d:%02d sec\n",
- dirs, files, sumSizes / 1E6, duration / 60, duration % 60);
+ fprintf(m_output, i18n(
+ "=== copied: %d file(s) with %.6f MByte in %02d:%02d sec. Tree: %d dir(s) %d file(s) %.6f MByte\n"),
+ files, sumSizes / 1E6, duration / 60, duration % 60,
+ treeDirs, treeFiles, treeSumSizes / 1E6);
}
} catch(ReOptionException& exc){
help(exc.getMessage());
m_base(base),\r
// m_dirs\r
m_passNoForDirSearch(2),\r
- m_dirPatterns(NULL)\r
+ m_dirPatterns(NULL),\r
+ m_directories(0),\r
+ m_files(0),\r
+ m_sizes(0ll)\r
+\r
{\r
memset(m_dirs, 0, sizeof m_dirs);\r
m_dirs[0] = new ReDirStatus_t();\r
ReDirStatus_t* ReTraverser::rawNextFile(int& level)\r
{\r
ReDirStatus_t* rc = NULL;\r
- bool alreadyRead = false;\r
+ bool alreadyRead = false;\r
bool again;\r
do{\r
again = false;\r
if (m_level < 0){\r
- // Not yet initialized?\r
- if (m_dirs[0]->m_passNo == 2)\r
- rc = NULL;\r
- else {\r
- // first call:\r
+ // Not yet initialized?\r
+ if (m_dirs[0]->m_passNo == 2)\r
+ rc = NULL;\r
+ else {\r
+ // first call:\r
if (initEntry(m_base.str(), NULL, 0)){\r
- if (1 != m_passNoForDirSearch)\r
+ m_directories++;\r
+ if (1 != m_passNoForDirSearch)\r
rc = m_dirs[0];\r
- else\r
- again = alreadyRead = true;\r
- }\r
- }\r
+ else\r
+ again = alreadyRead = true;\r
+ }\r
+ }\r
} else {\r
ReDirStatus_t* current = m_dirs[m_level];\r
if (alreadyRead || current->findNext()){\r
- alreadyRead = false;\r
+ alreadyRead = false;\r
// a file or directory found:\r
if (current->m_passNo != m_passNoForDirSearch){\r
// we search for any file:\r
current->node()))){\r
// open a new level\r
alreadyRead = initEntry(current->m_path, current->node() , m_level + 1);\r
+ m_directories++;\r
}\r
}\r
} else {\r
}\r
}\r
}\r
- if (rc != NULL && rc->isDotDir())\r
- again = true;\r
+ if (rc != NULL && rc->isDotDir())\r
+ again = true;\r
} while(again);\r
- level = m_level;\r
+ if (rc != NULL && ! rc->isDirectory()){\r
+ m_files++;\r
+ if (m_sizes >= 0)\r
+ m_sizes += rc->fileSize();\r
+ }\r
+ level = m_level;\r
return rc;\r
}\r
/**\r
*/\r
ReDirStatus_t* ReTraverser::topOfStack(int offsetFromTop){\r
ReDirStatus_t* rc = NULL;\r
- if (offsetFromTop >= 0 && m_level - offsetFromTop >= 0)\r
- rc = m_dirs[m_level - offsetFromTop];\r
+ if (offsetFromTop >= 0 && m_level - 1 - offsetFromTop >= 0)\r
+ rc = m_dirs[m_level - 1 - offsetFromTop];\r
return rc;\r
}\r