Skip to content

Commit

Permalink
Escape single qutoes in shell script paths
Browse files Browse the repository at this point in the history
  • Loading branch information
valters-tomsons committed May 1, 2023
1 parent dce59b2 commit 6cf3bcb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/DayZLauncher.UnixPatcher.Utils/UnixJunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static UnixJunctions()

public static void Create(string junctionPoint, string targetDir, bool overwrite)
{
Console.WriteLine("UnixJunctions: Create() called junctionPoint='" + junctionPoint + "' ; targetDir='" + targetDir + "'");

targetDir = Path.GetFullPath(targetDir);

if (Directory.Exists(junctionPoint) || File.Exists(junctionPoint))
Expand All @@ -36,11 +38,16 @@ public static void Create(string junctionPoint, string targetDir, bool overwrite
junctionPoint = ToUnixPath(junctionPoint);
targetDir = ToUnixPath(targetDir);

junctionPoint = EscapeSingleQutoes(junctionPoint);
targetDir = EscapeSingleQutoes(targetDir);

RunShellCommand("ln", $"-s -T '{targetDir}' '{junctionPoint}'");
}

public static void Delete(string junctionPoint)
{
Console.WriteLine("UnixJunctions: Delete() called junctionPoint='" + junctionPoint + "'");

if (!Directory.Exists(junctionPoint))
{
if (File.Exists(junctionPoint))
Expand All @@ -53,12 +60,15 @@ public static void Delete(string junctionPoint)
if (Directory.Exists(junctionPoint))
{
junctionPoint = ToUnixPath(junctionPoint);
junctionPoint = EscapeSingleQutoes(junctionPoint);
RunShellCommand("rm", $"-r '{junctionPoint}'");
}
}

public static bool Exists(string path)
{
Console.WriteLine("UnixJunctions: Exists() called path='" + path + "'");

if (!Directory.Exists(path))
{
return false;
Expand All @@ -67,6 +77,7 @@ public static bool Exists(string path)
try
{
path = ToUnixPath(path);
path = EscapeSingleQutoes(path);
string output = RunShellCommand("ls", $"-la '{path}'");
return output.Contains("->");
}
Expand All @@ -78,7 +89,10 @@ public static bool Exists(string path)

public static string GetTarget(string junctionPoint)
{
Console.WriteLine("UnixJunctions: GetTarget() called junctionPoint='" + junctionPoint + "'");

junctionPoint = ToUnixPath(junctionPoint);
junctionPoint = EscapeSingleQutoes(junctionPoint);
string output = RunShellCommand("readlink", $"'{junctionPoint}'");
return output.Trim();
}
Expand Down Expand Up @@ -151,4 +165,9 @@ private static string ToUnixPath(string windowsPath)
{
return windowsPath.Replace("Z:", string.Empty).Replace("\\", "/");
}

private static string EscapeSingleQutoes(string path)
{
return path.Replace("'", @"'\''");
}
}

0 comments on commit 6cf3bcb

Please sign in to comment.