Skip to content

Commit

Permalink
Search all distinct drive id's rather than just default drive id for …
Browse files Browse the repository at this point in the history
…--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
  • Loading branch information
abraunegg committed Jan 20, 2021
1 parent 525504f commit 6b0b6a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
14 changes: 14 additions & 0 deletions src/itemdb.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
38 changes: 22 additions & 16 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -5529,25 +5529,31 @@ 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)) {
// File is in the local database cache
JSONValue fileDetails;

try {
fileDetails = onedrive.getFileDetails(item.driveId, item.id);
} catch (OneDriveException e) {
// display what the error is
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
return;
}
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) {
// display what the error is
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
return;
}

if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
// Valid JSON object
writeln(fileDetails["webUrl"].str);
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
// 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);
}
Expand Down

0 comments on commit 6b0b6a6

Please sign in to comment.