rc = QObject::tr("file can be read only partitionally: %1 [%2/%3]")
.arg(source).arg(totalBytes).arg(filesize);
if (rc.isEmpty()){
- if (! setTimes(target2, sourceInfo->lastModified(),
+ if (! setTimes(target2, sourceInfo->lastModified(),
sourceInfo->lastRead()))
rc = QObject::tr("cannot set date/time (%1): %2")
.arg(errno).arg(target);
#endif
return rc;
}
+/**
+ * Sets the filetimes.
+ *
+ * @param filename name of the file to change
+ * @param modified the new modification time
+ * @param accessed the new access time.
+ * If <code>m_undefinedTime</code> the current time is taken
+ * @param logger the logger
+ * @return <code>true</code>: success
+ */
+ bool ReFileUtils::setTimes(const QString& filename, const QDateTime& modified,
+ const QDateTime& accessed, ReLogger* logger) {
+ bool rc = true;
+#if defined _WIN32
+ // utime does not work with VS10-32-bit
+ FILETIME accessed2 = unixTimeToFileTime(accessed.toMSecsSinceEpoch());
+ FILETIME modified2 = unixTimeToFileTime(modified.toMSecsSinceEpoch());
+ const ushort* name = filename.utf16();
+
+ HANDLE handle = CreateFileW(reinterpret_cast<const WCHAR*>(name), GENERIC_WRITE, FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (handle == INVALID_HANDLE_VALUE){
+ if (logger != NULL)
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_2,
+ "cannot open file for time change (%d): %s", GetLastError(), filename);
+ rc = false;
+ } else if (! SetFileTime(handle, NULL, &accessed2, &modified2)){
+ rc = false;
+ if (logger != NULL)
+ logger->logv(LOG_ERROR, LOC_SET_TIMES_1,
+ "cannot change times (%d): %s", errno, filename);
+ CloseHandle(handle);
+ }
+#else
+ rc = setTimes(I18N::s2b(filename).constData(), modified, accessed, logger);
+#endif
+ return rc;
+}
+
+ bool rc = true;
/** Sets the read position of a file.
* @param file file to process
ReLogger* logger = NULL);
static bool setTimes(const char* filename, const QDateTime& modified,
const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
+ static bool setTimes(const QString& filename, const QDateTime& modified,
+ const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
static void splitUrl(const QString& url, QString* protocol, QString* host,
QString* path, QString* node, QString* params = NULL);
static int64_t tell(FILE* file);