mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-15 18:37:55 +08:00
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
This commit is contained in:
committed by
Richard Hua
parent
4bba4ce88f
commit
72cb03df39
@@ -45,11 +45,10 @@ namespace CodePush.ReactNative
|
||||
try
|
||||
{
|
||||
// Unzip the downloaded file and then delete the zip
|
||||
var unzippedFolder = await GetUnzippedFolderAsync().ConfigureAwait(false);
|
||||
var unzippedFolder = await CreateUnzippedFolderAsync().ConfigureAwait(false);
|
||||
/**
|
||||
* TODO:
|
||||
* 1) ZipFile.ExtractToDirectory is not reliable and throws exception if:
|
||||
* - folder exists already
|
||||
* - path is too long (> 250 chars)
|
||||
*
|
||||
* 2) Un-zipping is quite long operation. Does it make sense for async?
|
||||
@@ -292,9 +291,16 @@ namespace CodePush.ReactNative
|
||||
return await codePushFolder.CreateFileAsync(CodePushConstants.StatusFileName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<IFolder> GetUnzippedFolderAsync()
|
||||
private async Task<IFolder> CreateUnzippedFolderAsync()
|
||||
{
|
||||
var codePushFolder = await UpdateUtils.GetCodePushFolderAsync().ConfigureAwait(false);
|
||||
var isUnzippedFolderExists = await codePushFolder.CheckExistsAsync(CodePushConstants.UnzippedFolderName).ConfigureAwait(false);
|
||||
|
||||
if (isUnzippedFolderExists != ExistenceCheckResult.NotFound)
|
||||
{
|
||||
await codePushFolder.GetFolderAsync(CodePushConstants.UnzippedFolderName).ContinueWith((existingFolder) => existingFolder.Result.DeleteAsync());
|
||||
}
|
||||
|
||||
return await codePushFolder.CreateFolderAsync(CodePushConstants.UnzippedFolderName, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace CodePush.ReactNative
|
||||
try
|
||||
{
|
||||
// Unzip the downloaded file and then delete the zip
|
||||
StorageFolder unzippedFolder = await GetUnzippedFolderAsync().ConfigureAwait(false);
|
||||
StorageFolder unzippedFolder = await CreateUnzippedFolderAsync().ConfigureAwait(false);
|
||||
ZipFile.ExtractToDirectory(downloadFile.Path, unzippedFolder.Path);
|
||||
await downloadFile.DeleteAsync().AsTask().ConfigureAwait(false);
|
||||
|
||||
@@ -99,7 +99,6 @@ namespace CodePush.ReactNative
|
||||
await downloadFile.MoveAsync(newUpdateFolder).AsTask().ConfigureAwait(false);
|
||||
}
|
||||
/*TODO: ZipFile.ExtractToDirectory is not reliable and throws exceptions if:
|
||||
- folder exists already
|
||||
- path is too long
|
||||
it needs to be handled
|
||||
*/
|
||||
@@ -278,9 +277,16 @@ namespace CodePush.ReactNative
|
||||
return await codePushFolder.CreateFileAsync(CodePushConstants.StatusFileName, CreationCollisionOption.OpenIfExists).AsTask().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<StorageFolder> GetUnzippedFolderAsync()
|
||||
private async Task<StorageFolder> CreateUnzippedFolderAsync()
|
||||
{
|
||||
StorageFolder codePushFolder = await GetCodePushFolderAsync().ConfigureAwait(false);
|
||||
var unzippedFolder = await codePushFolder.TryGetItemAsync(CodePushConstants.UnzippedFolderName).AsTask().ConfigureAwait(false);
|
||||
|
||||
if (unzippedFolder != null)
|
||||
{
|
||||
await unzippedFolder.DeleteAsync();
|
||||
}
|
||||
|
||||
return await codePushFolder.CreateFolderAsync(CodePushConstants.UnzippedFolderName, CreationCollisionOption.OpenIfExists).AsTask().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user