Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the moving of Shared Folder Links to other folders #3052

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
file,
dir,
remote,
root,
unknown
}

Expand Down Expand Up @@ -127,21 +128,21 @@
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 @@

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;
Fixed Show fixed Hide fixed
string selctRemoteTypeByRemoteDriveIdStmt;
Fixed Show fixed Hide fixed
string deleteItemByIdStmt;
bool databaseInitialised = false;
private Mutex databaseLock;
Expand Down Expand Up @@ -352,6 +356,23 @@
FROM item
WHERE remoteDriveId = ?1 AND remoteId = ?2
";
selectItemByRemoteDriveIdStmt = "
SELECT *
FROM item
WHERE remoteDriveId = ?1
";
selctRemoteTypeByNameStmt = "
Fixed Show fixed Hide fixed
SELECT *
FROM item
WHERE type = 'remote'
AND name = ?1
";
selctRemoteTypeByRemoteDriveIdStmt = "
Fixed Show fixed Hide fixed
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 @@
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);
Fixed Show fixed Hide fixed
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) {
Fixed Show fixed Hide fixed
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 @@
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 @@
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 @@
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
Loading