diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java index 321258d76..535e095e1 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ChmodAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 IBM Corporation and others. + * Copyright (c) 2008, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Red Hat Incorporated - initial API and implementation * IBM Corporation - ongoing development * Cloudsmith Inc - ongoing development + * Landmark Graphics Corporation - bug 397183 *******************************************************************************/ package org.eclipse.equinox.internal.p2.touchpoint.natives.actions; @@ -25,23 +26,52 @@ public class ChmodAction extends ProvisioningAction { private static final String ACTION_CHMOD = "chmod"; //$NON-NLS-1$ private static final boolean WINDOWS = java.io.File.separatorChar == '\\'; + // target targetFile absoluteFiles + // Y Y Y can't set all these arguments + // Y Y N Y -> today, add the ability to specifty a list of fileNames + // Y N Y warning? targetFolder unecessary + // Y N N incorrect, missing targetFile + // N Y Y incorrect, target file can't be with absoluteFiles + // N Y N incorrect, missing the targetFolder + // N N Y Y + // N N N public IStatus execute(Map<String, Object> parameters) { + Object absoluteFiles = parameters.get(ActionConstants.PARM_ABSOLUTE_FILES); //String or String[] String targetDir = (String) parameters.get(ActionConstants.PARM_TARGET_DIR); - if (targetDir == null) - return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_DIR, ACTION_CHMOD)); String targetFile = (String) parameters.get(ActionConstants.PARM_TARGET_FILE); - if (targetFile == null) + + if (targetFile != null && absoluteFiles != null) + return Util.createError(Messages.chmod_param_cant_be_set_together); + + if (targetDir != null && targetFile == null) return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_FILE, ACTION_CHMOD)); + + if (targetDir == null && targetFile != null) + return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET_DIR, ACTION_CHMOD)); + String permissions = (String) parameters.get(ActionConstants.PARM_PERMISSIONS); if (permissions == null) return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_PERMISSIONS, ACTION_CHMOD)); String optionsString = (String) parameters.get(ActionConstants.PARM_OPTIONS); - // Check that file exist - File probe = new File(targetDir + IPath.SEPARATOR + targetFile); - if (!probe.exists()) - return Util.createError(NLS.bind(Messages.action_0_failed_file_1_doesNotExist, ACTION_CHMOD, probe.toString())); + String[] filesToProcess = absoluteFiles != null ? ((absoluteFiles instanceof String) ? new String[] {(String) absoluteFiles} : (String[]) absoluteFiles) : makeFilesAbsolute(targetDir, targetFile); + for (String fileToChmod : filesToProcess) { + // Check that file exist + File probe = new File(fileToChmod); + if (!probe.exists()) + return Util.createError(NLS.bind(Messages.action_0_failed_file_1_doesNotExist, ACTION_CHMOD, probe.toString())); + + doChmod(fileToChmod, permissions, optionsString); + } + + return Status.OK_STATUS; + } + private String[] makeFilesAbsolute(String targetDir, String targetFile) { + return new String[] {new String(targetDir + IPath.SEPARATOR + targetFile)}; + } + + private void doChmod(String fileToChmod, String permissions, String optionsString) { String options[] = null; if (optionsString != null) { ArrayList<String> collect = new ArrayList<String>(); @@ -63,8 +93,7 @@ public class ChmodAction extends ProvisioningAction { } } - chmod(targetDir, targetFile, permissions, options); - return Status.OK_STATUS; + chmod(fileToChmod, permissions, options); } public IStatus undo(Map<String, Object> parameters) { @@ -72,7 +101,7 @@ public class ChmodAction extends ProvisioningAction { return Status.OK_STATUS; } - public void chmod(String targetDir, String targetFile, String perms, String[] options) { + public void chmod(String fileToChmod, String perms, String[] options) { if (WINDOWS) return; Runtime r = Runtime.getRuntime(); @@ -86,7 +115,7 @@ public class ChmodAction extends ProvisioningAction { args[i++] = options[j]; } args[i++] = perms; - args[i] = targetDir + IPath.SEPARATOR + targetFile; + args[i] = fileToChmod; Process process = r.exec(args); readOffStream(process.getErrorStream()); readOffStream(process.getInputStream()); |