Skip to content

Commit

Permalink
Merge pull request #298 Mac: Support projecting symbolic links
Browse files Browse the repository at this point in the history
Mac: Support projecting symbolic links
  • Loading branch information
wilbaker authored Oct 2, 2018
2 parents ff96c28 + 01bc65b commit 6ba9eb0
Show file tree
Hide file tree
Showing 23 changed files with 903 additions and 104 deletions.
4 changes: 2 additions & 2 deletions GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public virtual void DeleteDirectory(string path, bool recursive = false)
RecursiveDelete(path);
}

public virtual bool IsSymlink(string path)
public virtual bool IsSymLink(string path)
{
return (this.GetAttributes(path) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint && NativeMethods.IsSymlink(path);
return (this.GetAttributes(path) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint && NativeMethods.IsSymLink(path);
}

public virtual IEnumerable<DirectoryItemInfo> ItemsInDirectory(string path)
Expand Down
1 change: 1 addition & 0 deletions GVFS/GVFS.Common/Git/GVFSGitObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum RequestSource
FileStreamCallback,
GVFSVerb,
NamedPipeMessage,
SymLinkCreation,
}

protected GVFSContext Context { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static uint GetWindowsBuildNumber()
return versionInfo.BuildNumber;
}

public static bool IsSymlink(string path)
public static bool IsSymLink(string path)
{
using (SafeFileHandle output = CreateFile(
path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ private void PerformIOBeforePlaceholderDatabaseUpgradeTest()
this.fileSystem.DeleteDirectory(Path.Combine(this.Enlistment.RepoRoot, "GVFS\\GVFS.Tests\\Properties"));

string junctionTarget = Path.Combine(this.Enlistment.EnlistmentRoot, "DirJunction");
string symlinkTarget = Path.Combine(this.Enlistment.EnlistmentRoot, "DirSymlink");
string symLinkTarget = Path.Combine(this.Enlistment.EnlistmentRoot, "DirSymLink");
Directory.CreateDirectory(junctionTarget);
Directory.CreateDirectory(symlinkTarget);
Directory.CreateDirectory(symLinkTarget);

string junctionLink = Path.Combine(this.Enlistment.RepoRoot, "DirJunction");
string symlink = Path.Combine(this.Enlistment.RepoRoot, "DirLink");
string symLink = Path.Combine(this.Enlistment.RepoRoot, "DirLink");
ProcessHelper.Run("CMD.exe", "/C mklink /J " + junctionLink + " " + junctionTarget);
ProcessHelper.Run("CMD.exe", "/C mklink /D " + symlink + " " + symlinkTarget);
ProcessHelper.Run("CMD.exe", "/C mklink /D " + symLink + " " + symLinkTarget);

string target = Path.Combine(this.Enlistment.EnlistmentRoot, "GVFS", "GVFS", "GVFS.UnitTests");
string link = Path.Combine(this.Enlistment.RepoRoot, "UnitTests");
Expand Down
56 changes: 46 additions & 10 deletions GVFS/GVFS.FunctionalTests/FileSystemRunners/BashRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public BashRunner()
}
}

private enum FileType
{
Invalid,
File,
Directory,
SymLink,
}

protected override string FileName
{
get
Expand Down Expand Up @@ -86,15 +94,22 @@ public static void DeleteDirectoryWithUnlimitedRetries(string path)
}
}

public override bool FileExists(string path)
public bool IsSymbolicLink(string path)
{
string bashPath = this.ConvertWinPathToBashPath(path);
return this.FileExistsOnDisk(path, FileType.SymLink);
}

string command = string.Format("-c \"[ -f {0} ] && echo {1} || echo {2}\"", bashPath, ShellRunner.SuccessOutput, ShellRunner.FailureOutput);
public void CreateSymbolicLink(string newLinkFilePath, string existingFilePath)
{
string existingFileBashPath = this.ConvertWinPathToBashPath(existingFilePath);
string newLinkBashPath = this.ConvertWinPathToBashPath(newLinkFilePath);

string output = this.RunProcess(command).Trim();
this.RunProcess(string.Format("-c \"ln -s -F {0} {1}\"", existingFileBashPath, newLinkBashPath));
}

return output.Equals(ShellRunner.SuccessOutput, StringComparison.InvariantCulture);
public override bool FileExists(string path)
{
return this.FileExistsOnDisk(path, FileType.File);
}

public override string MoveFile(string sourcePath, string targetPath)
Expand Down Expand Up @@ -187,11 +202,7 @@ public override void WriteAllTextShouldFail<ExceptionType>(string path, string c

public override bool DirectoryExists(string path)
{
string bashPath = this.ConvertWinPathToBashPath(path);

string output = this.RunProcess(string.Format("-c \"[ -d {0} ] && echo {1} || echo {2}\"", bashPath, ShellRunner.SuccessOutput, ShellRunner.FailureOutput)).Trim();

return output.Equals(ShellRunner.SuccessOutput, StringComparison.InvariantCulture);
return this.FileExistsOnDisk(path, FileType.Directory);
}

public override void MoveDirectory(string sourcePath, string targetPath)
Expand Down Expand Up @@ -267,6 +278,31 @@ public override void DeleteDirectory_ShouldBeBlockedByProcess(string path)
Assert.Fail("Unlike the other runners, bash.exe does not check folder handle before recusively deleting");
}

private bool FileExistsOnDisk(string path, FileType type)
{
string checkArgument = string.Empty;
switch (type)
{
case FileType.File:
checkArgument = "-f";
break;
case FileType.Directory:
checkArgument = "-d";
break;
case FileType.SymLink:
checkArgument = "-h";
break;
default:
Assert.Fail($"{nameof(FileExistsOnDisk)} does not support {nameof(FileType)} {type}");
break;
}

string bashPath = this.ConvertWinPathToBashPath(path);
string command = $"-c \"[ {checkArgument} {bashPath} ] && echo {ShellRunner.SuccessOutput} || echo {ShellRunner.FailureOutput}\"";
string output = this.RunProcess(command).Trim();
return output.Equals(ShellRunner.SuccessOutput, StringComparison.InvariantCulture);
}

private string ConvertWinPathToBashPath(string winPath)
{
string bashPath = string.Concat("/", winPath);
Expand Down
Loading

0 comments on commit 6ba9eb0

Please sign in to comment.