m_values.clear();
}
+/**
+ * Writes the content of the list into a stream.
+ *
+ * @param stream OUT: output stream
+ * @param prefix NULL or a string which is written first
+ */
+void ReHashList::dump(FILE* stream, const char* prefix){
+ if (prefix != NULL)
+ fprintf(stream, "%s\n", prefix);
+ ReArrayPosition position;
+ ReByteBuffer key, value;
+ while(next(position, &key, &value)){
+ fprintf(stream, "%s : [%3d] %s\n", key.str(), value.length(), value.str());
+ }
+}
+
/** @brief Returns the index of key.
*
* @param key The byte sequence of the key.
*/
void ReDirSync::copyFile(ReDirStatus_t* entry, const char* target){
copyFile(entry->fullName(), entry->filetimeToTime(entry->modified()),
+ entry->filetimeToTime(entry->accessed()),
entry->fileSize(), target, m_buffer, ReLogger::globalLogger());
}
/**
*
* @param source the source file name
* @param modified 0 or modification time
+ * @param accessed 0 or the access time
* @param size -1 or filesize
* @param target the name of the target file
* @param buffer OUT: the reading uses this buffer<br>
* Set the capacity to make it more efficient
* @param logger NULL or the logger for error messages
*/
-bool ReDirSync::copyFile(const char* source, time_t modified, int64_t size,
+bool ReDirSync::copyFile(const char* source, time_t modified,
+ time_t accessed, int64_t size,
const char* target, ReByteBuffer& buffer, ReLogger* logger){
bool rc = false;
#ifdef __linux__
- if (size < 0ll){
+ if (size < 0ll || modified == 0){
struct stat info;
- if (stat(source, &info) == 0)
+ if (stat(source, &info) == 0){
size = info.st_size;
+ modified = info.st_mtime;
+ accessed = info.st_atime;
+ }
else if (logger != NULL)
logger->sayF(LOG_ERROR, LC_COPY_FILE_1,
i18n("could not find: $ (errno: $2)")).arg(source).arg(errno).end();
i18n("cannot open $1 (errno: $2)"))
.arg(target).arg(errno).end();
} else{
- // Reserve the space:
- if (fseek(fpTarget, size, SEEK_SET) != size){
- if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_4,
- i18n("cannot reserve space for $1 (errno: $2)"))
- .arg(target).arg(errno).end();
- } else {
- fseek(fpTarget, 0, SEEK_SET);
- while(size > 0){
- size_t blockSize = buffer.capacity();
- if ((int) blockSize > size)
- blockSize = size;
- if (fread(buffer.buffer(), blockSize, 1, fpSource) != 1){
- if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_5,
- i18n("cannot read $1 (errno: $2)"))
- .arg(source).arg(errno).end();
- break;
- }
- if (fwrite(buffer.buffer(), 1, blockSize, fpSource) != 1){
- if (logger != NULL)
- logger->sayF(LOG_ERROR, LC_COPY_FILE_6,
- i18n("cannot write $1 (errno: $2)"))
- .arg(target).arg(errno).end();
- break;
- }
- size -= blockSize;
+ while(size > 0){
+ size_t blockSize = buffer.capacity();
+ if ((int) blockSize > size)
+ blockSize = size;
+ if (fread(buffer.buffer(), blockSize, 1, fpSource) != 1){
+ if (logger != NULL)
+ logger->sayF(LOG_ERROR, LC_COPY_FILE_5,
+ i18n("cannot read $1 (errno: $2)"))
+ .arg(source).arg(errno).end();
+ break;
+ }
+ size_t written;
+ if ((written = fwrite(buffer.buffer(), 1, blockSize,
+ fpTarget)) != blockSize){
+ if (logger != NULL)
+ logger->sayF(LOG_ERROR, LC_COPY_FILE_6,
+ i18n("cannot write $1 [$2] (errno: $3)"))
+ .arg(target).arg(written).arg(errno).end();
+ break;
}
+ size -= blockSize;
}
rc = size == 0ll;
fclose(fpTarget);
+
+ struct utimbuf times;
+
+ times.actime = accessed;
+ times.modtime = modified;
+ utime(target, ×);
}
fclose(fpSource);
}