Improved code.

This commit is contained in:
Christian P. MOMON 2018-05-31 10:34:24 +02:00
parent f7bb3a764d
commit 4087330039

View file

@ -64,7 +64,7 @@ public class Unix
{
try
{
sudo("bash", "-c", "echo \"" + text + "\" >> " + path);
bash(String.format("echo \"%s\" >> %s", text, path));
}
catch (CmdExecException exception)
{
@ -86,7 +86,7 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
result = CmdExecUtils.run(BASH + " -c " + command);
}
@ -103,7 +103,7 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
result = CmdExecUtils.run(BASH + " -c " + command);
}
@ -140,8 +140,8 @@ public class Unix
{
try
{
// CmdExec.run(SUDO, "chmod", changes, path);
sudo("chmod", changes, path);
// CmdExec.run(BASH, "chmod", changes, path);
bash("chmod", changes, path);
}
catch (CmdExecException exception)
{
@ -383,9 +383,9 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
result = CmdExecUtils.run(SUDO + " " + command);
result = CmdExecUtils.run(command);
}
else
{
@ -483,6 +483,7 @@ public class Unix
public static void link(final String sourcePath, final String targetPath) throws UnixException
{
logger.info("[{}][{}]", sourcePath, targetPath);
if ((sourcePath == null) || (sourcePath.length() == 0) || (targetPath == null) || (targetPath.length() == 0))
{
throw new IllegalArgumentException("Parameter undefined: [" + sourcePath + "][" + targetPath + "].");
@ -825,7 +826,7 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
result = CmdExecUtils.run(SUDO + " " + command);
}
@ -851,7 +852,7 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
String[] newCommand = ArrayUtils.add(command, 0, SUDO);
result = CmdExecUtils.run(newCommand);
@ -878,7 +879,7 @@ public class Unix
{
String result;
if (SystemUtils.IS_OS_LINUX)
if (SystemUtils.IS_OS_UNIX)
{
result = CmdExecUtils.run(BASH + " -c " + command);
}
@ -891,6 +892,40 @@ public class Unix
return result;
}
/**
* Sudo chmod.
*
* @param changes
* the changes
* @param path
* the path
* @throws UnixException
* the unix exception
*/
public static void sudoChmod(final String changes, final String path) throws UnixException
{
if ((changes == null) || (changes.length() == 0) || (path == null) || (path.length() == 0))
{
throw new IllegalArgumentException("Parameter undefined: [" + changes + "][" + path + "].");
}
else if (!new File(path).exists())
{
throw new IllegalArgumentException("Path not found: [" + path + "].");
}
else
{
try
{
// CmdExec.run(SUDO, "chmod", changes, path);
sudo("chmod", changes, path);
}
catch (CmdExecException exception)
{
throw new UnixException("Error running chmod command for [" + changes + "][" + path + "].", exception);
}
}
}
/**
* Unlink.
*