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

Fix backups not working in the root directory. Fixes #327. #376

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -166,6 +171,9 @@ public async Task<IEnumerable<StorageProviderItem>> GetChildrenByParentItem(Stor

public async Task<IEnumerable<StorageProviderItem>> 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)
Expand Down