Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 72cb03d

Browse files
ymusiychuk-lohikaRichard Hua
authored andcommitted
Ensure that unzipped folder does not exist before unzip on Windows (#732)
* Ensure that Unzipped folder does not exists before unzip * Updated comment * Renamed InitUnzippedFolderAsync -> CreateUnzippedFolderAsync, getFolder -> existingFolder
1 parent 4bba4ce commit 72cb03d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

windows/CodePush.Net46/UpdateManager.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ internal async Task DownloadPackageAsync(JObject updatePackage, string expectedB
4545
try
4646
{
4747
// Unzip the downloaded file and then delete the zip
48-
var unzippedFolder = await GetUnzippedFolderAsync().ConfigureAwait(false);
48+
var unzippedFolder = await CreateUnzippedFolderAsync().ConfigureAwait(false);
4949
/**
5050
* TODO:
5151
* 1) ZipFile.ExtractToDirectory is not reliable and throws exception if:
52-
* - folder exists already
5352
* - path is too long (> 250 chars)
5453
*
5554
* 2) Un-zipping is quite long operation. Does it make sense for async?
@@ -292,9 +291,16 @@ private async Task<IFile> GetStatusFileAsync()
292291
return await codePushFolder.CreateFileAsync(CodePushConstants.StatusFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
293292
}
294293

295-
private async Task<IFolder> GetUnzippedFolderAsync()
294+
private async Task<IFolder> CreateUnzippedFolderAsync()
296295
{
297296
var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
297+
var isUnzippedFolderExists = await codePushFolder.CheckExistsAsync(CodePushConstants.UnzippedFolderName).ConfigureAwait(false);
298+
299+
if (isUnzippedFolderExists != ExistenceCheckResult.NotFound)
300+
{
301+
await codePushFolder.GetFolderAsync(CodePushConstants.UnzippedFolderName).ContinueWith((existingFolder) => existingFolder.Result.DeleteAsync());
302+
}
303+
298304
return await codePushFolder.CreateFolderAsync(CodePushConstants.UnzippedFolderName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
299305
}
300306

windows/CodePush/UpdateManager.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal async Task DownloadPackageAsync(JObject updatePackage, string expectedB
5353
try
5454
{
5555
// Unzip the downloaded file and then delete the zip
56-
StorageFolder unzippedFolder = await GetUnzippedFolderAsync().ConfigureAwait(false);
56+
StorageFolder unzippedFolder = await CreateUnzippedFolderAsync().ConfigureAwait(false);
5757
ZipFile.ExtractToDirectory(downloadFile.Path, unzippedFolder.Path);
5858
await downloadFile.DeleteAsync().AsTask().ConfigureAwait(false);
5959

@@ -99,7 +99,6 @@ internal async Task DownloadPackageAsync(JObject updatePackage, string expectedB
9999
await downloadFile.MoveAsync(newUpdateFolder).AsTask().ConfigureAwait(false);
100100
}
101101
/*TODO: ZipFile.ExtractToDirectory is not reliable and throws exceptions if:
102-
- folder exists already
103102
- path is too long
104103
it needs to be handled
105104
*/
@@ -278,9 +277,16 @@ private async Task<StorageFile> GetStatusFileAsync()
278277
return await codePushFolder.CreateFileAsync(CodePushConstants.StatusFileName, CreationCollisionOption.OpenIfExists).AsTask().ConfigureAwait(false);
279278
}
280279

281-
private async Task<StorageFolder> GetUnzippedFolderAsync()
280+
private async Task<StorageFolder> CreateUnzippedFolderAsync()
282281
{
283282
StorageFolder codePushFolder = await GetCodePushFolderAsync().ConfigureAwait(false);
283+
var unzippedFolder = await codePushFolder.TryGetItemAsync(CodePushConstants.UnzippedFolderName).AsTask().ConfigureAwait(false);
284+
285+
if (unzippedFolder != null)
286+
{
287+
await unzippedFolder.DeleteAsync();
288+
}
289+
284290
return await codePushFolder.CreateFolderAsync(CodePushConstants.UnzippedFolderName, CreationCollisionOption.OpenIfExists).AsTask().ConfigureAwait(false);
285291
}
286292

0 commit comments

Comments
 (0)