mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(archival): ♻ extract GetTargetFile
This commit is contained in:
parent
24d8dc045f
commit
68b6b297f6
1 changed files with 23 additions and 11 deletions
|
|
@ -32,7 +32,7 @@ public GitListArchiveRepository(
|
|||
|
||||
public async Task AddAsync(ListArchive listArchive, CancellationToken cancellationToken)
|
||||
{
|
||||
int segmentCount = 0;
|
||||
var segmentNumber = 1;
|
||||
await foreach (var segment in listArchive.Segments.WithCancellation(cancellationToken))
|
||||
{
|
||||
var strategy = segment.GetStrategy<IStreamToPlainTextConversionStrategy>();
|
||||
|
|
@ -45,14 +45,9 @@ public async Task AddAsync(ListArchive listArchive, CancellationToken cancellati
|
|||
return;
|
||||
}
|
||||
|
||||
string targetExtension;
|
||||
if (segment.Extension.IsPlainText)
|
||||
var fileInfo = GetTargetFile(listArchive.TargetFileName, segmentNumber, segment.Extension);
|
||||
if (fileInfo is default(FileInfo))
|
||||
{
|
||||
targetExtension = segment.Extension.IsMeaningfulToConsumer ? segment.Extension.Value : ".txt";
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement
|
||||
_logger.LogWarning(
|
||||
"Writing from non-plain text extension {Extension} for target {Target} not yet supported. Skipping list",
|
||||
segment.Extension,
|
||||
|
|
@ -60,8 +55,6 @@ public async Task AddAsync(ListArchive listArchive, CancellationToken cancellati
|
|||
return;
|
||||
}
|
||||
|
||||
var targetFileName = listArchive.TargetFileName + (segmentCount == 0 ? string.Empty : $"-{segmentCount}") + targetExtension;
|
||||
var fileInfo = new FileInfo(Path.Combine(_options.RepositoryPath, targetFileName));
|
||||
_writtenFiles.Add(fileInfo);
|
||||
|
||||
_logger.LogInformation("Writing {FileName}", fileInfo.Name);
|
||||
|
|
@ -71,7 +64,7 @@ public async Task AddAsync(ListArchive listArchive, CancellationToken cancellati
|
|||
|
||||
_logger.LogInformation("Finished writing {FileName}", fileInfo.Name);
|
||||
|
||||
segmentCount++;
|
||||
segmentNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,5 +98,24 @@ public void Dispose()
|
|||
|
||||
_repo.CheckoutPaths("HEAD", _writtenFiles.Select(f => f.Name));
|
||||
}
|
||||
|
||||
private FileInfo? GetTargetFile(string baseTargetFileName, int segmentNumber, ListFileExtension extension)
|
||||
{
|
||||
string targetExtension;
|
||||
if (extension.IsPlainText)
|
||||
{
|
||||
targetExtension = extension.IsMeaningfulToConsumer ? extension.Value : ".txt";
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement
|
||||
return default;
|
||||
}
|
||||
|
||||
var targetFileName = baseTargetFileName +
|
||||
(segmentNumber == 1 ? string.Empty : $"-{segmentNumber}") +
|
||||
targetExtension;
|
||||
return new FileInfo(Path.Combine(_options.RepositoryPath, targetFileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue