mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-02 14:12:52 +02:00
Search all distinct drive id's rather than just default drive id for --get-file-link (#1230)
* Add new DB query to return distinct driveId's from database * Use all distinct drive ID's to query if path is in-sync with OneDrive before attempting to retreive the item file link from OneDrive
This commit is contained in:
parent
525504f91a
commit
6b0b6a66f7
14
src/itemdb.d
14
src/itemdb.d
|
@ -484,4 +484,18 @@ final class ItemDatabase
|
|||
auto stmt = db.prepare("VACUUM;");
|
||||
stmt.exec();
|
||||
}
|
||||
|
||||
// Select distinct driveId items from database
|
||||
string[] selectDistinctDriveIds()
|
||||
{
|
||||
string[] driveIdArray;
|
||||
auto stmt = db.prepare("SELECT DISTINCT driveId FROM item;");
|
||||
auto res = stmt.exec();
|
||||
if (res.empty) return driveIdArray;
|
||||
while (!res.empty) {
|
||||
driveIdArray ~= res.front[0].dup;
|
||||
res.step();
|
||||
}
|
||||
return driveIdArray;
|
||||
}
|
||||
}
|
||||
|
|
14
src/sync.d
14
src/sync.d
|
@ -5529,12 +5529,15 @@ final class SyncEngine
|
|||
if (exists(localFilePath)) {
|
||||
// File exists locally, does it exist in the database
|
||||
// Path needs to be relative to sync_dir path
|
||||
string relativePath = relativePath(localFilePath, syncDir);
|
||||
Item item;
|
||||
if (itemdb.selectByPath(relativePath, defaultDriveId, item)) {
|
||||
string[] distinctDriveIds = itemdb.selectDistinctDriveIds();
|
||||
string relativePath = relativePath(localFilePath, syncDir);
|
||||
bool fileInDB = false;
|
||||
foreach (searchDriveId; distinctDriveIds) {
|
||||
if (itemdb.selectByPath(relativePath, searchDriveId, item)) {
|
||||
// File is in the local database cache
|
||||
fileInDB = true;
|
||||
JSONValue fileDetails;
|
||||
|
||||
try {
|
||||
fileDetails = onedrive.getFileDetails(item.driveId, item.id);
|
||||
} catch (OneDriveException e) {
|
||||
|
@ -5547,7 +5550,10 @@ final class SyncEngine
|
|||
// Valid JSON object
|
||||
writeln(fileDetails["webUrl"].str);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
// was file found?
|
||||
if (!fileInDB) {
|
||||
// File has not been synced with OneDrive
|
||||
log.error("File has not been synced with OneDrive: ", localFilePath);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue