Skip to content

Commit

Permalink
fix: copy files instead of moving them
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 22, 2024
1 parent f5a55ff commit 5f20467
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ internal class DownloadTask : IDisposable {
private bool SupportsHardLinks { get; set; }

/// <summary>
/// A mapping of existing file paths to their hashes.
/// A mapping of existing file paths to their hashes. Paths are relative.
/// </summary>
private IReadOnlyDictionary<string, string> ExistingPathHashes { get; set; } = new Dictionary<string, string>();

/// <summary>
/// A mapping of existing hashes to their file paths.
/// A mapping of existing hashes to their file paths. Paths are relative.
/// </summary>
private IReadOnlyDictionary<string, string> ExistingHashPaths { get; set; } = new Dictionary<string, string>();

Expand Down Expand Up @@ -740,7 +740,7 @@ internal static string[] GetOutputPaths(IReadOnlyCollection<List<string?>> files

private async Task DuplicateFile(string filesDir, IEnumerable<string> outputPaths, string path) {
if (!this.SupportsHardLinks) {
// if hard links aren't supported, move the path to the first output
// if hard links aren't supported, copy the path to the first output
// path
var firstPath = outputPaths.FirstOrDefault();
if (firstPath == null) {
Expand All @@ -753,7 +753,7 @@ private async Task DuplicateFile(string filesDir, IEnumerable<string> outputPath
}

// ReSharper disable once AccessToModifiedClosure
Plugin.Resilience.Execute(() => File.Move(path, dest));
Plugin.Resilience.Execute(() => File.Copy(path, dest));
path = dest;
return;
}
Expand Down Expand Up @@ -842,6 +842,7 @@ private async Task DownloadFile(Uri baseUri, string filesPath, string[] outputPa

// find an existing path that has this hash
if (this.ExistingHashPaths.TryGetValue(hash, out var validPath)) {
validPath = Path.Join(filesPath, validPath);
goto Duplicate;
}

Expand Down

0 comments on commit 5f20467

Please sign in to comment.