diff --git a/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs b/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs index 9b1a08c..7a047cb 100644 --- a/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs +++ b/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs @@ -88,18 +88,26 @@ public async Task Copy(string sourcePath, string destPath) if (sourceFile == null) throw new FileNotFoundException("Google Drive: File not found.", sourcePath); + var destFilename = CloudPath.GetFileName(destPath); var destFolder = CloudPath.GetDirectoryName(destPath); var parentFolder = await api.GetFileByPath(destFolder, true); if (parentFolder == null) throw new FileNotFoundException("Google Drive: File not found.", destFolder); - - var destFilename = CloudPath.GetFileName(destPath); var destFile = new File { Name = destFilename, - Parents = new[] {parentFolder.Id} + Parents = new[] { "root" } }; + if (!string.IsNullOrEmpty(destFolder)) + { + var parentFolder = await api.GetFileByPath(destFolder); + if (parentFolder == null) + throw new FileNotFoundException("Google Drive: File not found.", destFolder); + + destFile.Parents = new[] { parentFolder.Id }; + } + var result = await api.Files.Copy(destFile, sourceFile.Id).ExecuteAsync(); } @@ -157,6 +165,9 @@ public async Task> GetChildrenByParentItem(Stor public async Task> GetChildrenByParentPath(string path) { + if (string.IsNullOrEmpty(path)) + return await GetChildrenByParentItem(await GetRootItem()); + var api = await GetApi(); var item = await api.GetFileByPath(path, true); if (item == null)