return;
static_assert(ItemTypeVirtualFile == 4 && ItemTypeVirtualFileDownload == 5, "");
- SqlQuery query("UPDATE metadata SET type=5 WHERE " IS_PREFIX_PATH_OF("?1", "path") " AND type=4;", _db);
+ SqlQuery query("UPDATE metadata SET type=5 WHERE "
+ "(" IS_PREFIX_PATH_OF("?1", "path") " OR ?1 == '') "
+ "AND type=4;", _db);
query.bindValue(1, path);
query.exec();
// We also must make sure we do not read the files from the database (same logic as in avoidReadFromDbOnNextSync)
// This includes all the parents up to the root, but also all the directory within the selected dir.
static_assert(ItemTypeDirectory == 2, "");
- query.prepare("UPDATE metadata SET md5='_invalid_' WHERE (" IS_PREFIX_PATH_OF("?1", "path") " OR " IS_PREFIX_PATH_OR_EQUAL("path", "?1") ") AND type == 2;");
+ query.prepare("UPDATE metadata SET md5='_invalid_' WHERE "
+ "(" IS_PREFIX_PATH_OF("?1", "path") " OR ?1 == '' OR " IS_PREFIX_PATH_OR_EQUAL("path", "?1") ") AND type == 2;");
query.bindValue(1, path);
query.exec();
}
auto &query = _wipePinStateQuery;
ASSERT(query.initOrReset(QByteArrayLiteral(
- "DELETE FROM flags WHERE " IS_PREFIX_PATH_OR_EQUAL("?1", "path") ";"),
+ "DELETE FROM flags WHERE "
+ // Allow "" to delete everything
+ " (" IS_PREFIX_PATH_OR_EQUAL("?1", "path") " OR ?1 == '');"),
_db));
query.bindValue(1, path);
query.exec();
/**
* Set the 'ItemTypeVirtualFileDownload' to all the files that have the ItemTypeVirtualFile flag
* within the directory specified path path
+ *
+ * The path "" marks everything.
*/
void markVirtualFileForDownloadRecursively(const QByteArray &path);
* Wipes pin states for a path and below.
*
* Used when the user asks a subtree to have a particular pin state.
+ * The path "" wipes every entry.
*/
void wipePinStateForPathAndBelow(const QByteArray &path);
// Set in the database that we should download the file
SyncJournalFileRecord record;
_journal.getFileRecord(relativepath, &record);
- if (!record.isValid())
+ if (!record.isValid() && !relativepath.isEmpty())
return;
if (record._type == ItemTypeVirtualFile) {
record._type = ItemTypeVirtualFileDownload;
_journal.setFileRecord(record);
// Make sure we go over that file during the discovery
_journal.avoidReadFromDbOnNextSync(relativepath);
- } else if (record._type == ItemTypeDirectory) {
+ } else if (record._type == ItemTypeDirectory || relativepath.isEmpty()) {
_journal.markVirtualFileForDownloadRecursively(relativepath);
} else {
qCWarning(lcFolder) << "Invalid existing record " << record._type << " for file " << _relativepath;
SyncJournalFileRecord record;
_journal.getFileRecord(relativepath, &record);
- if (!record.isValid())
+ if (!record.isValid() && !relativepath.isEmpty())
return;
if (record._type == ItemTypeFile) {
markForDehydration(record);
- } else if (record._type == ItemTypeDirectory) {
+ } else if (record._type == ItemTypeDirectory || relativepath.isEmpty()) {
_journal.getFilesBelowPath(relativepath, markForDehydration);
} else {
qCWarning(lcFolder) << "Invalid existing record " << record._type << " for file " << _relativepath;
/**
* Mark a virtual file as being ready for download, and start a sync.
* relativepath is the path to the file (including the extension)
+ * Passing a folder means that all contained virtual items shall be downloaded.
+ * A relative path of "" downloads everything.
*/
void downloadVirtualFile(const QString &relativepath);
*
* relativepath is the path to the file
* It's allowed to pass a path to a folder: all contained files will be dehydrated.
+ * A relative path of "" dehydrates everything.
*/
void dehydrateFile(const QString &relativepath);
QCOMPARE(getRaw("local/local"), PinState::Inherited);
QCOMPARE(getRaw("local/local/local"), PinState::Inherited);
QCOMPARE(getRaw("local/local/online"), PinState::Inherited);
+
+ // Wiping everything
+ _db.wipePinStateForPathAndBelow("");
+ QCOMPARE(getRaw(""), PinState::Inherited);
+ QCOMPARE(getRaw("local"), PinState::Inherited);
+ QCOMPARE(getRaw("online"), PinState::Inherited);
}
private: