diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index bdecd3399c12..915a798fb09f 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -470,6 +470,83 @@ if (IS_WIN) { } } +/** + * Copies a directory and its children. First it tries nsIFile::CopyTo on the + * source directory and if that fails it will fall back to recursing. + * + * @param aSrcDir + * nsIFile for the source directory to be copied from. + * @param aDestDir + * nsIFile for the destination directory parent. + * @param aDestLeafName + * the destination directory name. + */ +function copyDirRecursive(aSrcDir, aDestDir, aDestLeafName) { + try { + aSrcDir.copyTo(aDestDir, aDestLeafName); + return; + } + catch (e) { + logTestInfo("copyTo error - src path: " + aSrcDir.path + ", dest path: " + + aDestDir.path + ", dir name: " + aDestLeafName + + ", exception: " + e); + } + + let destDir = aDestDir.clone(); + destDir.append(aDestLeafName); + if (!destDir.exists()) { + try { + destDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); + } + catch (e) { + logTestInfo("unable to create directory, path: " + destDir.path + + ", exception: " + e); + do_throw(e); + } + } + var dirEntries = aSrcDir.directoryEntries; + while (dirEntries.hasMoreElements()) { + let entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); + + if (entry.isDirectory()) { + copyDirRecursive(entry, destDir, entry.leafName); + } + else { + let destFile = destDir.clone(); + destFile.append(entry.leafName); + if (destFile.exists()) { + try { + destFile.remove(false); + } + catch (e) { + logTestInfo("unable to remove file, path: " + destFile.path + + ", exception: " + e); + let bakFile = destDir.clone(); + bakFile.append(entry.leafName + ".bak"); + logTestInfo("attempting moveTo of file, src path: " + destFile.path + + ", dest path: " + bakFile.path + ", exception: " + e); + try { + destFile.moveTo(destDir, bakFile.leafName); + } + catch (e) { + logTestInfo("unable to move file, src path: " + destFile.path + + ", dest path: " + bakFile.path + ", exception: " + e); + do_throw(e); + } + } + } + try { + entry.copyTo(destDir, entry.leafName); + } + catch (e) { + logTestInfo("unable to copy file, src path: " + entry.path + + ", dest path: " + destFile.path + ", exception: " + e); + do_throw(e); + } + } + } +} + /** * Helper function for updater tests for launching the updater binary to apply * a mar file. diff --git a/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js b/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js index e8b3db8716fb..a96e305ff93b 100644 --- a/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js +++ b/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js @@ -303,7 +303,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir; diff --git a/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js b/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js index 9ac1b6618aca..cc12b847e087 100644 --- a/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js +++ b/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js @@ -238,7 +238,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir; diff --git a/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js b/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js index d2424af2cf64..c655ceef3ab5 100644 --- a/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js +++ b/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js @@ -332,7 +332,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir; diff --git a/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js index b3ac0a8b6b24..a1eb4f4597a9 100644 --- a/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js +++ b/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js @@ -309,7 +309,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir; diff --git a/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js index f165f357bb68..ec03a3807d52 100644 --- a/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js +++ b/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js @@ -247,7 +247,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir; diff --git a/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js index fca5aef3d4e6..4d77c41ebb3b 100644 --- a/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js +++ b/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js @@ -335,7 +335,7 @@ function adjustPathsOnWindows() { tmpDir.append("ExecutableDir.tmp"); tmpDir.createUnique(tmpDir.DIRECTORY_TYPE, 0755); let procDir = getCurrentProcessDir(); - procDir.copyTo(tmpDir, "bin"); + copyDirRecursive(procDir, tmpDir, "bin"); let newDir = tmpDir.clone(); newDir.append("bin"); gWindowsBinDir = newDir;