Skip to content

Commit

Permalink
Implement Feature Request #2824
Browse files Browse the repository at this point in the history
* Implement Feature Request #2824 to support the moving of Shared Folder Links to other folders
  • Loading branch information
abraunegg committed Dec 26, 2024
1 parent 71a71da commit 0e7315e
Show file tree
Hide file tree
Showing 3 changed files with 526 additions and 127 deletions.
93 changes: 89 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 selctRemoteTypeByNameStmt;

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

selct is not a recognized word. (unrecognized-spelling)
string selctRemoteTypeByRemoteDriveIdStmt;

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

selct is not a recognized word. (unrecognized-spelling)
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
";
selctRemoteTypeByNameStmt = "

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

selct is not a recognized word. (unrecognized-spelling)
SELECT *
FROM item
WHERE type = 'remote'
AND name = ?1
";
selctRemoteTypeByRemoteDriveIdStmt = "

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

selct is not a recognized word. (unrecognized-spelling)
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,68 @@ 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(selctRemoteTypeByNameStmt);

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

selct is not a recognized word. (unrecognized-spelling)
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 selctRemoteTypeByRemoteDriveId(const(char)[] entryName, out Item item) {
synchronized(databaseLock) {
auto p = db.prepare(selctRemoteTypeByRemoteDriveIdStmt);
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 +776,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 +796,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 +869,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 0e7315e

Please sign in to comment.