Skip to content

Commit

Permalink
If the RZFS link folder is somehow not a symbolic link, recursive del…
Browse files Browse the repository at this point in the history
…ete it (#118)
  • Loading branch information
hach-que authored Jan 1, 2025
1 parent a1f713a commit e0fe734
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions UET/Redpoint.Uet.Workspace/PhysicalWorkspaceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,31 @@ private async Task<IWorkspace> AllocateRemoteZfsAsync(RemoteZfsWorkspaceDescript
_parameterGenerator.ConstructReservationParameters(descriptor.TemplateId)).ConfigureAwait(false);
try
{
if (Directory.Exists(Path.Combine(reservation.ReservedPath, "S")))
var linkFolder = Path.Combine(reservation.ReservedPath, "S");
var linkInfo = new DirectoryInfo(linkFolder);
if (linkInfo.Exists)
{
Directory.Delete(Path.Combine(reservation.ReservedPath, "S"));
if (linkInfo.LinkTarget != null)
{
// Just delete the symbolic link.
linkInfo.Delete();
}
else
{
// Some process wrote to a path under the symbolic link after it was removed and turned it into a real directory. Nuke it.
_logger.LogWarning($"Detected '{linkInfo.FullName}' is not a symbolic link; removing recursively!");
await DirectoryAsync.DeleteAsync(linkInfo.FullName, true).ConfigureAwait(false);
}
}

var targetPath = string.IsNullOrWhiteSpace(descriptor.Subpath)
? response.ResponseStream.Current.WindowsShareRemotePath
: Path.Combine(response.ResponseStream.Current.WindowsShareRemotePath, descriptor.Subpath);
Directory.CreateSymbolicLink(
Path.Combine(reservation.ReservedPath, "S"),
linkFolder,
targetPath);

_logger.LogInformation($"Remote ZFS workspace '{targetPath}' is now available at '{Path.Combine(reservation.ReservedPath, "S")}'.");
_logger.LogInformation($"Remote ZFS workspace '{targetPath}' is now available at '{linkFolder}'.");

return new RemoteZfsWorkspace(response, reservation);
}
Expand Down

0 comments on commit e0fe734

Please sign in to comment.