Skip to content

Set WorkingDirectory for background mount process to avoid holding caller's CWD handle#2029

Merged
tyrielv merged 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-cwd-handle
Jun 17, 2026
Merged

Set WorkingDirectory for background mount process to avoid holding caller's CWD handle#2029
tyrielv merged 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-cwd-handle

Conversation

@tyrielv

@tyrielv tyrielv commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

When running gvfs clone or gvfs mount, the background GVFS.Mount.exe process inherits the caller's current working directory. This holds a handle on that directory, preventing the caller from cleaning up or deleting it afterward.

This is a problem for bootstrapping tools that launch gvfs and then need to remove themselves.

Fix

Set ProcessStartInfo.WorkingDirectory to the directory containing the mount executable (programName). Since the mount process only uses its command-line arguments (which are already absolute paths) to locate the enlistment, it has no dependency on the inherited CWD.

Validation

  • GVFS.Platform.Windows builds cleanly
  • GVFS.UnitTests builds cleanly
  • All paths passed to the background process are already absolute (mountExecutableLocation is built from ProcessHelper.GetCurrentProcessLocation(), and mountPath comes from enlistment.EnlistmentRoot / enlistment.WorkingDirectoryRoot)

The background mount process (GVFS.Mount.exe) inherits the caller's
current working directory, holding a handle that prevents the caller
from cleaning up or deleting that directory. This affects tools that
launch gvfs clone/mount and need to remove themselves afterward.

Set ProcessStartInfo.WorkingDirectory to the program's own directory
so the child process does not hold a handle on the caller's CWD.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv marked this pull request as ready for review June 17, 2026 21:01
@tyrielv tyrielv enabled auto-merge June 17, 2026 21:34
@tyrielv tyrielv merged commit 59a66c3 into microsoft:master Jun 17, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants