Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the RZFS link folder is somehow not a symbolic link, recursive delete it #118

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading