Skip to content

Commit

Permalink
add missing cancellationTokens for directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Juhasz committed Jan 1, 2025
1 parent 4a26dc6 commit 910515d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/PhotoArchiver/Archiver.Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<RetrieveResult> RetrieveAsync(BlobContainerClient container, I
}

// download
var targetFile = await directory.CreateFileAsync(Path.GetFileName(blob.Name));
var targetFile = await directory.CreateFileAsync(Path.GetFileName(blob.Name), cancellationToken);
result = await DownloadCoreAsync(targetFile, blob, blobClient, Options.Verify, cancellationToken);
}
catch (RequestFailedException ex)
Expand Down
2 changes: 1 addition & 1 deletion src/PhotoArchiver/Archiver.Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<ArchiveResult> ArchiveAsync(IDirectory directory, IProgressInd
{
// set up filter
var matcher = new Matcher().AddInclude(Options.SearchPattern);
var files = await directory.GetFilesAsync();
var files = await directory.GetFilesAsync(cancellationToken);

var query = files.Where(f => matcher.Match(directory.Path, f.Path).HasMatches)
.OrderBy(f => f.Path)
Expand Down
6 changes: 3 additions & 3 deletions src/PhotoArchiver/Files/IDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public interface IDirectory

string Path { get; }

Task<IReadOnlyList<IFile>> GetFilesAsync();
Task<IReadOnlyList<IFile>> GetFilesAsync(CancellationToken cancellationToken);

Task<IFile> GetFileAsync(string name);
Task<IFile> GetFileAsync(string name, CancellationToken cancellationToken);

Task<IFile> CreateFileAsync(string name);
Task<IFile> CreateFileAsync(string name, CancellationToken cancellationToken);
}
10 changes: 5 additions & 5 deletions src/PhotoArchiver/Files/SystemIODirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public SystemIODirectory(string path)
public string Path => Directory.FullName;


public Task<IFile> CreateFileAsync(string name)
public async Task<IFile> CreateFileAsync(string name, CancellationToken cancellationToken)
{
var file = new FileInfo(System.IO.Path.Combine(Directory.FullName, name));
file.Create().Dispose();
return Task.FromResult(new SystemIOFile(file) as IFile);
await using var _ = file.Create();
return new SystemIOFile(file);
}

public Task<IFile> GetFileAsync(string name)
public Task<IFile> GetFileAsync(string name, CancellationToken cancellationToken)
{
return Task.FromResult(new SystemIOFile(new FileInfo(System.IO.Path.Combine(Directory.FullName, name))) as IFile);
}

public Task<IReadOnlyList<IFile>> GetFilesAsync()
public Task<IReadOnlyList<IFile>> GetFilesAsync(CancellationToken cancellationToken)
{
return Task.FromResult(Directory.GetFiles("*", SearchOption.AllDirectories).Select(f => new SystemIOFile(f)).ToList() as IReadOnlyList<IFile>);
}
Expand Down

0 comments on commit 910515d

Please sign in to comment.