Skip to content

Commit

Permalink
Support adding SharePoint Libraries as Shared Folder Links (#3051)
Browse files Browse the repository at this point in the history
* Support adding SharePoint Libraries as Shared Folder Links
* Remove section of code that is no longer used
* Be consistent in log output for Personal Accounts, despite personal accounts not supporting relocatable Shared Folder links
* Update /delta generation message to include the driveId
* Ensure 'skip_dir' rules are correctly applied to remote shared folder links
  • Loading branch information
abraunegg authored Jan 10, 2025
1 parent 71a71da commit 5a20154
Show file tree
Hide file tree
Showing 3 changed files with 542 additions and 134 deletions.
92 changes: 88 additions & 4 deletions src/itemdb.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum ItemType {
file,
dir,
remote,
root,
unknown
}

Expand Down Expand Up @@ -127,21 +128,21 @@ Item makeDatabaseItem(JSONValue driveItem) {
bool typeSet = false;
if (isItemFile(driveItem)) {
// 'file' object exists in the JSON
if (debugLogging) {addLogEntry("Flagging object as a file", ["debug"]);}
if (debugLogging) {addLogEntry("Flagging database item.type as a file", ["debug"]);}
typeSet = true;
item.type = ItemType.file;
}

if (isItemFolder(driveItem)) {
// 'folder' object exists in the JSON
if (debugLogging) {addLogEntry("Flagging object as a directory", ["debug"]);}
if (debugLogging) {addLogEntry("Flagging database item.type as a directory", ["debug"]);}
typeSet = true;
item.type = ItemType.dir;
}

if (isItemRemote(driveItem)) {
// 'remote' object exists in the JSON
if (debugLogging) {addLogEntry("Flagging object as a remote", ["debug"]);}
if (debugLogging) {addLogEntry("Flagging database item.type as a remote", ["debug"]);}
typeSet = true;
item.type = ItemType.remote;
}
Expand Down Expand Up @@ -224,14 +225,17 @@ Item makeDatabaseItem(JSONValue driveItem) {

final class ItemDatabase {
// increment this for every change in the db schema
immutable int itemDatabaseVersion = 14;
immutable int itemDatabaseVersion = 15;

Database db;
string insertItemStmt;
string updateItemStmt;
string selectItemByIdStmt;
string selectItemByRemoteIdStmt;
string selectItemByRemoteDriveIdStmt;
string selectItemByParentIdStmt;
string selectRemoteTypeByNameStmt;
string selectRemoteTypeByRemoteDriveIdStmt;
string deleteItemByIdStmt;
bool databaseInitialised = false;
private Mutex databaseLock;
Expand Down Expand Up @@ -352,6 +356,23 @@ final class ItemDatabase {
FROM item
WHERE remoteDriveId = ?1 AND remoteId = ?2
";
selectItemByRemoteDriveIdStmt = "
SELECT *
FROM item
WHERE remoteDriveId = ?1
";
selectRemoteTypeByNameStmt = "
SELECT *
FROM item
WHERE type = 'remote'
AND name = ?1
";
selectRemoteTypeByRemoteDriveIdStmt = "
SELECT *
FROM item
WHERE type = 'remote'
AND remoteDriveId = ?1
";
selectItemByParentIdStmt = "SELECT * FROM item WHERE driveId = ? AND parentId = ?";
deleteItemByIdStmt = "DELETE FROM item WHERE driveId = ? AND id = ?";

Expand Down Expand Up @@ -571,7 +592,67 @@ final class ItemDatabase {
return false;
}
}

// This should return the 'remote' DB entry for a given remote drive id
bool selectByRemoteDriveId(const(char)[] remoteDriveId, out Item item) {
synchronized(databaseLock) {
auto p = db.prepare(selectItemByRemoteDriveIdStmt);
scope(exit) p.finalise(); // Ensure that the prepared statement is finalised after execution.
try {
p.bind(1, remoteDriveId);
auto r = p.exec();
if (!r.empty) {
item = buildItem(r);
return true;
}
} catch (SqliteException exception) {
// Handle the error appropriately
detailSQLErrorMessage(exception);
}
return false;
}
}

// This should return the 'remote' DB entry for the given 'name'
bool selectByRemoteEntryByName(const(char)[] entryName, out Item item) {
synchronized(databaseLock) {
auto p = db.prepare(selectRemoteTypeByNameStmt);
scope(exit) p.finalise(); // Ensure that the prepared statement is finalised after execution.
try {
p.bind(1, entryName);
auto r = p.exec();
if (!r.empty) {
item = buildItem(r);
return true;
}
} catch (SqliteException exception) {
// Handle the error appropriately
detailSQLErrorMessage(exception);
}
return false;
}
}

// This should return the 'remote' DB entry for the given 'remoteDriveId'
bool selectRemoteTypeByRemoteDriveId(const(char)[] entryName, out Item item) {
synchronized(databaseLock) {
auto p = db.prepare(selectRemoteTypeByRemoteDriveIdStmt);
scope(exit) p.finalise(); // Ensure that the prepared statement is finalised after execution.
try {
p.bind(1, entryName);
auto r = p.exec();
if (!r.empty) {
item = buildItem(r);
return true;
}
} catch (SqliteException exception) {
// Handle the error appropriately
detailSQLErrorMessage(exception);
}
return false;
}
}

// returns true if an item id is in the database
bool idInLocalDatabase(const(string) driveId, const(string) id) {
synchronized(databaseLock) {
Expand Down Expand Up @@ -694,6 +775,7 @@ final class ItemDatabase {
case file: typeStr = "file"; break;
case dir: typeStr = "dir"; break;
case remote: typeStr = "remote"; break;
case root: typeStr = "root"; break;
case unknown: typeStr = "unknown"; break;
case none: typeStr = null; break;
}
Expand All @@ -713,6 +795,7 @@ final class ItemDatabase {
case file: remoteTypeStr = "file"; break;
case dir: remoteTypeStr = "dir"; break;
case remote: remoteTypeStr = "remote"; break;
case root: remoteTypeStr = "root"; break;
case unknown: remoteTypeStr = "unknown"; break;
case none: remoteTypeStr = null; break;
}
Expand Down Expand Up @@ -785,6 +868,7 @@ final class ItemDatabase {
case "file": item.type = ItemType.file; break;
case "dir": item.type = ItemType.dir; break;
case "remote": item.type = ItemType.remote; break;
case "root": item.type = ItemType.root; break;
default: assert(0, "Invalid item type");
}

Expand Down
Loading

0 comments on commit 5a20154

Please sign in to comment.