@@ -34,25 +34,25 @@ public Task SavePackageFileAsync(Package package, Stream packageFile, bool overw
3434 throw new ArgumentNullException ( nameof ( packageFile ) ) ;
3535 }
3636
37- var fileName = BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
37+ var fileName = FileNameHelper . BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
3838 return _fileStorageService . SaveFileAsync ( _metadata . FileFolderName , fileName , packageFile , overwrite ) ;
3939 }
4040
4141 public Task < Stream > DownloadPackageFileAsync ( Package package )
4242 {
43- var fileName = BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
43+ var fileName = FileNameHelper . BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
4444 return _fileStorageService . GetFileAsync ( _metadata . FileFolderName , fileName ) ;
4545 }
4646
4747 public Task < Uri > GetPackageReadUriAsync ( Package package )
4848 {
49- var fileName = BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
49+ var fileName = FileNameHelper . BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
5050 return _fileStorageService . GetFileReadUriAsync ( _metadata . FileFolderName , fileName , endOfAccess : null ) ;
5151 }
5252
5353 public Task < bool > DoesPackageFileExistAsync ( Package package )
5454 {
55- var fileName = BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
55+ var fileName = FileNameHelper . BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
5656 return _fileStorageService . FileExistsAsync ( _metadata . FileFolderName , fileName ) ;
5757 }
5858
@@ -63,7 +63,7 @@ public Task SaveValidationPackageFileAsync(Package package, Stream packageFile)
6363 throw new ArgumentNullException ( nameof ( packageFile ) ) ;
6464 }
6565
66- var fileName = BuildFileName (
66+ var fileName = FileNameHelper . BuildFileName (
6767 package ,
6868 _metadata . FileSavePathTemplate ,
6969 _metadata . FileExtension ) ;
@@ -77,7 +77,7 @@ public Task SaveValidationPackageFileAsync(Package package, Stream packageFile)
7777
7878 public Task < Stream > DownloadValidationPackageFileAsync ( Package package )
7979 {
80- var fileName = BuildFileName (
80+ var fileName = FileNameHelper . BuildFileName (
8181 package ,
8282 _metadata . FileSavePathTemplate ,
8383 _metadata . FileExtension ) ;
@@ -93,7 +93,7 @@ public Task DeleteValidationPackageFileAsync(string id, string version)
9393 }
9494
9595 var normalizedVersion = NuGetVersionFormatter . Normalize ( version ) ;
96- var fileName = BuildFileName (
96+ var fileName = FileNameHelper . BuildFileName (
9797 id ,
9898 normalizedVersion ,
9999 _metadata . FileSavePathTemplate ,
@@ -116,15 +116,15 @@ public Task DeletePackageFileAsync(string id, string version)
116116
117117 var normalizedVersion = NuGetVersionFormatter . Normalize ( version ) ;
118118
119- var fileName = BuildFileName ( id , normalizedVersion , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
119+ var fileName = FileNameHelper . BuildFileName ( id , normalizedVersion , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
120120 return _fileStorageService . DeleteFileAsync ( _metadata . FileFolderName , fileName ) ;
121121 }
122122
123123 public Task < Uri > GetValidationPackageReadUriAsync ( Package package , DateTimeOffset endOfAccess )
124124 {
125125 package = package ?? throw new ArgumentNullException ( nameof ( package ) ) ;
126126
127- var fileName = BuildFileName (
127+ var fileName = FileNameHelper . BuildFileName (
128128 package ,
129129 _metadata . FileSavePathTemplate ,
130130 _metadata . FileExtension ) ;
@@ -134,7 +134,7 @@ public Task<Uri> GetValidationPackageReadUriAsync(Package package, DateTimeOffse
134134
135135 public Task < bool > DoesValidationPackageFileExistAsync ( Package package )
136136 {
137- var fileName = BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
137+ var fileName = FileNameHelper . BuildFileName ( package , _metadata . FileSavePathTemplate , _metadata . FileExtension ) ;
138138 return _fileStorageService . FileExistsAsync ( _metadata . ValidationFolderName , fileName ) ;
139139 }
140140
@@ -199,76 +199,6 @@ public async Task StorePackageFileInBackupLocationAsync(Package package, Stream
199199 }
200200 }
201201
202- public Task SaveLicenseFileAsync ( Package package , Stream licenseFile )
203- {
204- if ( package == null )
205- {
206- throw new ArgumentNullException ( nameof ( package ) ) ;
207- }
208-
209- if ( licenseFile == null )
210- {
211- throw new ArgumentNullException ( nameof ( licenseFile ) ) ;
212- }
213-
214- if ( package . EmbeddedLicenseType == EmbeddedLicenseFileType . Absent )
215- {
216- throw new ArgumentException ( "Package must have an embedded license" , nameof ( package ) ) ;
217- }
218-
219- var fileName = BuildLicenseFileName ( package ) ;
220-
221- // Gallery will generally ignore the content type on license files and will use the value from the DB,
222- // but we'll be nice and try to specify correct content type for them.
223- var contentType = package . EmbeddedLicenseType == EmbeddedLicenseFileType . Markdown
224- ? CoreConstants . MarkdownContentType
225- : CoreConstants . TextContentType ;
226-
227- return _fileStorageService . SaveFileAsync ( _metadata . PackageContentFolderName , fileName , contentType , licenseFile , overwrite : true ) ;
228- }
229-
230- public Task < Stream > DownloadLicenseFileAsync ( Package package )
231- {
232- var fileName = BuildLicenseFileName ( package ) ;
233- return _fileStorageService . GetFileAsync ( _metadata . PackageContentFolderName , fileName ) ;
234- }
235-
236- public Task DeleteLicenseFileAsync ( string id , string version )
237- {
238- if ( id == null )
239- {
240- throw new ArgumentNullException ( nameof ( id ) ) ;
241- }
242-
243- if ( string . IsNullOrWhiteSpace ( id ) )
244- {
245- throw new ArgumentException ( $ "{ nameof ( id ) } cannot be empty", nameof ( id ) ) ;
246- }
247-
248- if ( version == null )
249- {
250- throw new ArgumentNullException ( nameof ( version ) ) ;
251- }
252-
253- if ( string . IsNullOrWhiteSpace ( version ) )
254- {
255- throw new ArgumentException ( $ "{ nameof ( version ) } cannot be empty", nameof ( version ) ) ;
256- }
257-
258- var normalizedVersion = NuGetVersionFormatter . Normalize ( version ) ;
259- var fileName = BuildLicenseFileName ( id , normalizedVersion ) ;
260-
261- return _fileStorageService . DeleteFileAsync ( _metadata . PackageContentFolderName , fileName ) ;
262- }
263-
264- private string LicensePathTemplate => $ "{ _metadata . PackageContentPathTemplate } /{ CoreConstants . LicenseFileName } ";
265-
266- private string BuildLicenseFileName ( Package package )
267- => BuildFileName ( package , LicensePathTemplate , string . Empty ) ;
268-
269- private string BuildLicenseFileName ( string id , string version )
270- => BuildFileName ( id , version , LicensePathTemplate , string . Empty ) ;
271-
272202 private static string BuildBackupFileName ( string id , string version , string hash , string extension , string fileBackupSavePathTemplate )
273203 {
274204 if ( id == null )
@@ -296,51 +226,5 @@ private static string BuildBackupFileName(string id, string version, string hash
296226 HttpServerUtility . UrlTokenEncode ( hashBytes ) ,
297227 extension ) ;
298228 }
299-
300- protected static string BuildFileName ( Package package , string format , string extension )
301- {
302- if ( package == null )
303- {
304- throw new ArgumentNullException ( nameof ( package ) ) ;
305- }
306-
307- if ( package . PackageRegistration == null ||
308- String . IsNullOrWhiteSpace ( package . PackageRegistration . Id ) ||
309- ( String . IsNullOrWhiteSpace ( package . NormalizedVersion ) && String . IsNullOrWhiteSpace ( package . Version ) ) )
310- {
311- throw new ArgumentException ( CoreStrings . PackageIsMissingRequiredData , nameof ( package ) ) ;
312- }
313-
314- return BuildFileName (
315- package . PackageRegistration . Id ,
316- string . IsNullOrEmpty ( package . NormalizedVersion ) ?
317- NuGetVersionFormatter . Normalize ( package . Version ) :
318- package . NormalizedVersion , format , extension ) ;
319- }
320-
321- protected static string BuildFileName ( string id , string version , string pathTemplate , string extension )
322- {
323- if ( id == null )
324- {
325- throw new ArgumentNullException ( nameof ( id ) ) ;
326- }
327-
328- if ( version == null )
329- {
330- throw new ArgumentNullException ( nameof ( version ) ) ;
331- }
332-
333- // Note: packages should be saved and retrieved in blob storage using the lower case version of their filename because
334- // a) package IDs can and did change case over time
335- // b) blob storage is case sensitive
336- // c) we don't want to hit the database just to look up the right case
337- // and remember - version can contain letters too.
338- return String . Format (
339- CultureInfo . InvariantCulture ,
340- pathTemplate ,
341- id . ToLowerInvariant ( ) ,
342- version . ToLowerInvariant ( ) ,
343- extension ) ;
344- }
345229 }
346230}
0 commit comments