Give the tmp file a proper hidden and excluded name

This commit is contained in:
Olivier Goffart 2013-05-08 14:31:52 +02:00
parent 0b1ecd0ac6
commit ecd314cef5

View file

@ -33,7 +33,9 @@
#include <neon/ne_compress.h>
#include <neon/ne_redirect.h>
extern "C" int c_utimes(const char *, const struct timeval *); // this comes from csync
// We use some internals of csync:
extern "C" int c_utimes(const char *, const struct timeval *);
extern "C" void csync_win32_set_file_hidden( const char *file, bool h );
namespace Mirall {
@ -375,7 +377,12 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item,
_progressDb->remove(item._file);
}
if (tmpFileName.isEmpty()) {
tmpFileName = item._file + "." + QString::number(uint(qrand()), 16);
tmpFileName = item._file;
//add a dot at the begining of the filename to hide the file.
int slashPos = tmpFileName.lastIndexOf('/');
tmpFileName.insert(slashPos+1, '.');
//add the suffix
tmpFileName += ".~" + QString::number(uint(qrand()), 16);
}
QFile tmpFile(_localDir + tmpFileName);
@ -385,7 +392,7 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item,
return CSYNC_INSTRUCTION_ERROR;
}
//TODO: make tmpFile hidden and excluded in case it is still there in the next sync.
csync_win32_set_file_hidden(tmpFileName.toUtf8().constData(), true);
{
ProgressDatabase::DownloadInfo pi;
@ -477,6 +484,8 @@ csync_instructions_e OwncloudPropagator::downloadFile(const SyncFileItem &item,
}
}
csync_win32_set_file_hidden(tmpFileName.toUtf8().constData(), false);
// We want a rename that also overwite. QFile::rename does not overwite.
// Qt 5.1 has QFile::renameOverwrite we cold use. (Or even better: QSaveFile)
#ifndef QT_OS_WIN