@@ -39,7 +39,7 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
39
39
private readonly IMacroService _macroService ;
40
40
private readonly IContentTypeService _contentTypeService ;
41
41
private readonly string _tempFolderPath ;
42
- private readonly string _mediaFolderPath ;
42
+ private readonly string _createdPackagesFolderPath ;
43
43
44
44
/// <summary>
45
45
/// Initializes a new instance of the <see cref="CreatedPackageSchemaRepository"/> class.
@@ -76,9 +76,8 @@ public CreatedPackageSchemaRepository(
76
76
_macroService = macroService ;
77
77
_contentTypeService = contentTypeService ;
78
78
_xmlParser = new PackageDefinitionXmlParser ( ) ;
79
- _mediaFolderPath = mediaFolderPath ?? Path . Combine ( globalSettings . Value . UmbracoMediaPhysicalRootPath , Constants . SystemDirectories . CreatedPackages ) ;
80
- _tempFolderPath =
81
- tempFolderPath ?? Constants . SystemDirectories . TempData . EnsureEndsWith ( '/' ) + "PackageFiles" ;
79
+ _createdPackagesFolderPath = mediaFolderPath ?? Constants . SystemDirectories . CreatedPackages ;
80
+ _tempFolderPath = tempFolderPath ?? Constants . SystemDirectories . TempData + "/PackageFiles" ;
82
81
}
83
82
84
83
public IEnumerable < PackageDefinition > GetAll ( )
@@ -192,17 +191,12 @@ public bool SavePackage(PackageDefinition definition)
192
191
193
192
public string ExportPackage ( PackageDefinition definition )
194
193
{
195
-
196
194
// Ensure it's valid
197
195
ValidatePackage ( definition ) ;
198
196
199
197
// Create a folder for building this package
200
- var temporaryPath =
201
- _hostingEnvironment . MapPathContentRoot ( _tempFolderPath . EnsureEndsWith ( '/' ) + Guid . NewGuid ( ) ) ;
202
- if ( Directory . Exists ( temporaryPath ) == false )
203
- {
204
- Directory . CreateDirectory ( temporaryPath ) ;
205
- }
198
+ var temporaryPath = _hostingEnvironment . MapPathContentRoot ( Path . Combine ( _tempFolderPath , Guid . NewGuid ( ) . ToString ( ) ) ) ;
199
+ Directory . CreateDirectory ( temporaryPath ) ;
206
200
207
201
try
208
202
{
@@ -218,8 +212,7 @@ public string ExportPackage(PackageDefinition definition)
218
212
PackageTemplates ( definition , root ) ;
219
213
PackageStylesheets ( definition , root ) ;
220
214
PackageStaticFiles ( definition . Scripts , root , "Scripts" , "Script" , _fileSystems . ScriptsFileSystem ) ;
221
- PackageStaticFiles ( definition . PartialViews , root , "PartialViews" , "View" ,
222
- _fileSystems . PartialViewsFileSystem ) ;
215
+ PackageStaticFiles ( definition . PartialViews , root , "PartialViews" , "View" , _fileSystems . PartialViewsFileSystem ) ;
223
216
PackageMacros ( definition , root ) ;
224
217
PackageDictionaryItems ( definition , root ) ;
225
218
PackageLanguages ( definition , root ) ;
@@ -265,27 +258,25 @@ public string ExportPackage(PackageDefinition definition)
265
258
}
266
259
}
267
260
268
- var directoryName =
269
- _hostingEnvironment . MapPathWebRoot (
270
- Path . Combine ( _mediaFolderPath , definition . Name . Replace ( ' ' , '_' ) ) ) ;
271
-
272
- if ( Directory . Exists ( directoryName ) == false )
273
- {
274
- Directory . CreateDirectory ( directoryName ) ;
275
- }
261
+ var directoryName = _hostingEnvironment . MapPathContentRoot ( Path . Combine ( _createdPackagesFolderPath , definition . Name . Replace ( ' ' , '_' ) ) ) ;
262
+ Directory . CreateDirectory ( directoryName ) ;
276
263
277
264
var finalPackagePath = Path . Combine ( directoryName , fileName ) ;
278
265
279
- if ( File . Exists ( finalPackagePath ) )
266
+ // Clean existing files
267
+ foreach ( var packagePath in new [ ]
280
268
{
281
- File . Delete ( finalPackagePath ) ;
282
- }
283
-
284
- if ( File . Exists ( finalPackagePath . Replace ( "zip" , "xml" ) ) )
269
+ definition . PackagePath ,
270
+ finalPackagePath
271
+ } )
285
272
{
286
- File . Delete ( finalPackagePath . Replace ( "zip" , "xml" ) ) ;
273
+ if ( File . Exists ( packagePath ) )
274
+ {
275
+ File . Delete ( packagePath ) ;
276
+ }
287
277
}
288
278
279
+ // Move to final package path
289
280
File . Move ( tempPackagePath , finalPackagePath ) ;
290
281
291
282
definition . PackagePath = finalPackagePath ;
0 commit comments