Skip to content

Add ITemporaryPathProvider to allow more temp file customization - #1675

Merged
clairernovotny merged 4 commits into
NuGetPackageExplorer:mainfrom
joelverhagen:temp
Aug 12, 2024
Merged

clairernovotny merged 4 commits into
NuGetPackageExplorer:mainfrom
joelverhagen:temp

Conversation

@joelverhagen

Copy link
Copy Markdown
Contributor

My project (NuGet Insights) is getting alerts for some temp files generated by SymbolValidator. I can tell because ".npe" is seen in the file extension, per #1670. I would like a way of fully customizing the temporary files so I can enhance my logging, select specific temporary directory, etc.

using var getStream = await response.Content!.ReadAsStreamAsync().ConfigureAwait(false);
#endif
using var tempFile = new TemporaryFile(getStream, ".npe.snupkg");
using var tempFile = GetTemporaryFile(getStream, extension: ".npe.snupkg", name: fileName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to put .npe. in the filename instead of just using the original file name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to run until long path issues. .npe.nupkg is less likely than {long ID}.{long version}.snupkg. Additionally, the .snupkg temp file was never triggering the alerts. It was the assembly temp file case.

{
}

public SymbolValidator(IPackage package, string packagePath, IFolder? rootFolder, HttpClient? httpClient, ITemporaryFileProvider? tempProvider)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to have a default implementation of ITemporaryFileProvider registered in DI instead of null checks and if statements later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to make assumptions on what the temp file provider would do and instead leave the fully up to the user. Maybe if we get feedback from folks using the Core package on common usage patterns?

@clairernovotny
clairernovotny merged commit 829168b into NuGetPackageExplorer:main Aug 12, 2024
@joelverhagen
joelverhagen deleted the temp branch August 12, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants