Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2021-03-26 11:07:02 +0000
committerMickael Istria2021-03-26 20:48:55 +0000
commit1e5d4493d0884afc6d6f4a8789aa0eb79f23b7dc (patch)
tree0dc283da870be5928ac5fa0a29a792d6498bc3a1
parent36bd6d71cd035cb981ed18c0aa9b42af05205bcb (diff)
downloadrt.equinox.p2-1e5d4493d0884afc6d6f4a8789aa0eb79f23b7dc.tar.gz
rt.equinox.p2-1e5d4493d0884afc6d6f4a8789aa0eb79f23b7dc.tar.xz
rt.equinox.p2-1e5d4493d0884afc6d6f4a8789aa0eb79f23b7dc.zip
Bug 572289 - Fix CopyActionTestI20210326-1800
Change-Id: I253d5363605c385ddc372abf68dba8d018cea49e Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java43
2 files changed, 33 insertions, 19 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java
index 840c891b3..eaa8e60fc 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java
@@ -40,7 +40,8 @@ public class CleanupcopyAction extends ProvisioningAction {
/**
* Perform a cleanup of a previously made copy action.
- * @param parameters action parameters
+ *
+ * @param parameters action parameters
* @param restoreable flag indicating if the operation should be backed up
* @return status
*/
@@ -56,7 +57,7 @@ public class CleanupcopyAction extends ProvisioningAction {
IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU);
IProfile profile = (IProfile) parameters.get(ActionConstants.PARM_PROFILE);
- String copied = profile.getInstallableUnitProperty(iu, "copied" + ActionConstants.PIPE + source + ActionConstants.PIPE + target); //$NON-NLS-1$
+ String copied = profile.getInstallableUnitProperty(iu, CopyAction.buildCopiedFileIUPropertyKey(target, source));
if (copied == null)
return Status.OK_STATUS;
@@ -69,8 +70,8 @@ public class CleanupcopyAction extends ProvisioningAction {
if (!file.exists())
continue;
- //directories need to be deleted from the bottom-up, but directories are listed
- //in traversal order during copy, so we need to reverse the directory list
+ // directories need to be deleted from the bottom-up, but directories are listed
+ // in traversal order during copy, so we need to reverse the directory list
if (file.isDirectory())
directories.add(0, file);
else {
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java
index 2db21e894..94404fdf4 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java
@@ -26,12 +26,12 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.osgi.util.NLS;
/**
- * Copies from PARM_COPY_SOURCE to PARAM_COPY_TARGET
- * The optional parameter PARAM_COPY_OVERWRITE overwrites and existing file if set to true, else
- * and existing file with the same name is an error. The default is false.
- * If the source is a directory, a merge copy to the target is performed.
- * Copy will copy files and directories (recursively).
- *
+ * Copies from PARM_COPY_SOURCE to PARAM_COPY_TARGET The optional parameter
+ * PARAM_COPY_OVERWRITE overwrites and existing file if set to true, else and
+ * existing file with the same name is an error. The default is false. If the
+ * source is a directory, a merge copy to the target is performed. Copy will
+ * copy files and directories (recursively).
+ *
*/
public class CopyAction extends ProvisioningAction {
public static final String ID = "cp"; //$NON-NLS-1$
@@ -41,10 +41,11 @@ public class CopyAction extends ProvisioningAction {
return copy(parameters, true);
}
- /** Perform the copy.
+ /**
+ * Perform the copy.
*
- * @param parameters action parameters
- * @param restoreable flag indicating if the operation should be backed up
+ * @param parameters action parameters
+ * @param restoreable flag indicating if the operation should be backed up
* @return status
*/
public static IStatus copy(Map<String, Object> parameters, boolean restoreable) {
@@ -52,11 +53,13 @@ public class CopyAction extends ProvisioningAction {
IBackupStore backupStore = restoreable ? (IBackupStore) parameters.get(NativeTouchpoint.PARM_BACKUP) : null;
if (target == null)
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_TARGET, ID), null);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK,
+ NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_TARGET, ID), null);
String source = (String) parameters.get(ActionConstants.PARM_COPY_SOURCE);
if (source == null)
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_SOURCE, ID), null);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK,
+ NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_SOURCE, ID), null);
String overwrite = (String) parameters.get(ActionConstants.PARM_COPY_OVERWRITE);
Profile profile = (Profile) parameters.get(ActionConstants.PARM_PROFILE);
@@ -78,7 +81,8 @@ public class CopyAction extends ProvisioningAction {
try {
copiedFiles = mergeCopy(sourceFile, targetFile, Boolean.parseBoolean(overwrite), backupStore);
} catch (IOException e) {
- return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.copy_failed, sourceFile.getPath()), e);
+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK,
+ NLS.bind(Messages.copy_failed, sourceFile.getPath()), e);
}
// keep copied file in the profile as memento for CleanupCopy
StringBuffer copiedFileNameBuffer = new StringBuffer();
@@ -86,11 +90,16 @@ public class CopyAction extends ProvisioningAction {
copiedFileNameBuffer.append(copiedFile.getAbsolutePath()).append(ActionConstants.PIPE);
}
- profile.setInstallableUnitProperty(iu, "copied " + ActionConstants.PIPE + originalSource + ActionConstants.PIPE + target, copiedFileNameBuffer.toString()); //$NON-NLS-1$
+ profile.setInstallableUnitProperty(iu, buildCopiedFileIUPropertyKey(target, originalSource),
+ copiedFileNameBuffer.toString());
return Status.OK_STATUS;
}
+ static String buildCopiedFileIUPropertyKey(String target, String originalSource) {
+ return "copied" + ActionConstants.PIPE + originalSource + ActionConstants.PIPE + target; //$NON-NLS-1$
+ }
+
@Override
public IStatus undo(Map<String, Object> parameters) {
return CleanupcopyAction.cleanupcopy(parameters, false);
@@ -98,12 +107,14 @@ public class CopyAction extends ProvisioningAction {
/**
* Merge-copy file or directory.
+ *
* @param source
* @param target
* @param overwrite
* @throws IOException
*/
- private static File[] mergeCopy(File source, File target, boolean overwrite, IBackupStore backupStore) throws IOException {
+ private static File[] mergeCopy(File source, File target, boolean overwrite, IBackupStore backupStore)
+ throws IOException {
ArrayList<File> copiedFiles = new ArrayList<>();
xcopy(copiedFiles, source, target, overwrite, backupStore);
return copiedFiles.toArray(new File[copiedFiles.size()]);
@@ -111,13 +122,15 @@ public class CopyAction extends ProvisioningAction {
/**
* Merge-copy file or directory.
+ *
* @param copiedFiles - ArrayList where copied files are collected
* @param source
* @param target
* @param overwrite
* @throws IOException
*/
- private static void xcopy(ArrayList<File> copiedFiles, File source, File target, boolean overwrite, IBackupStore backupStore) throws IOException {
+ private static void xcopy(ArrayList<File> copiedFiles, File source, File target, boolean overwrite,
+ IBackupStore backupStore) throws IOException {
if (!source.exists())
throw new IOException("Source: " + source + " does not exists"); //$NON-NLS-1$//$NON-NLS-2$

Back to the top