diff --git a/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs b/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs index 97d06fa..19fd7b1 100644 --- a/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs +++ b/KeeAnywhere/StorageProviders/GoogleDrive/GoogleDriveStorageProvider.cs @@ -88,18 +88,23 @@ public async Task Copy(string sourcePath, string destPath) if (sourceFile == null) throw new FileNotFoundException("Google Drive: File not found.", sourcePath); - var destFolder = CloudPath.GetDirectoryName(destPath); - var parentFolder = await api.GetFileByPath(destFolder); - if (parentFolder == null) - throw new FileNotFoundException("Google Drive: File not found.", destFolder); - var destFilename = CloudPath.GetFileName(destPath); + var destFolder = CloudPath.GetDirectoryName(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(); } @@ -166,6 +171,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); if (item == null)