44using GVFS . Common . Tracing ;
55using GVFS . DiskLayoutUpgrades ;
66using System ;
7+ using System . Diagnostics ;
78using System . IO ;
89using System . Threading ;
910
@@ -12,6 +13,7 @@ namespace GVFS.CommandLine
1213 public class MountVerb : GVFSVerb . ForExistingEnlistment
1314 {
1415 private const string MountVerbName = "mount" ;
16+ private Process mountProcess ;
1517
1618 public string Verbosity { get ; set ; }
1719
@@ -197,9 +199,37 @@ protected override void Execute(GVFSEnlistment enlistment)
197199 ( ) => { return this . TryMount ( tracer , enlistment , mountExecutableLocation , out errorMessage ) ; } ,
198200 "Mounting" ) )
199201 {
200- this . ReportErrorAndExit ( tracer , errorMessage ) ;
202+ ReturnCode mountExitCode = ReturnCode . GenericError ;
203+ if ( this . mountProcess != null )
204+ {
205+ try
206+ {
207+ if ( ! this . mountProcess . HasExited )
208+ {
209+ this . mountProcess . WaitForExit ( 1000 ) ;
210+ }
211+
212+ if ( this . mountProcess . HasExited )
213+ {
214+ mountExitCode = ( ReturnCode ) this . mountProcess . ExitCode ;
215+ }
216+ }
217+ catch ( InvalidOperationException )
218+ {
219+ }
220+ finally
221+ {
222+ this . mountProcess . Dispose ( ) ;
223+ this . mountProcess = null ;
224+ }
225+ }
226+
227+ this . ReportErrorAndExit ( tracer , mountExitCode , errorMessage ) ;
201228 }
202229
230+ this . mountProcess ? . Dispose ( ) ;
231+ this . mountProcess = null ;
232+
203233 if ( ! this . Unattended )
204234 {
205235 tracer . RelatedInfo ( $ "{ nameof ( this . Execute ) } : Registering for automount") ;
@@ -229,7 +259,7 @@ private bool TryMount(ITracer tracer, GVFSEnlistment enlistment, string mountExe
229259
230260 tracer . RelatedInfo ( $ "{ nameof ( this . TryMount ) } : Launching background process('{ mountExecutableLocation } ') for { mountPath } ") ;
231261
232- GVFSPlatform . Instance . StartBackgroundVFS4GProcess (
262+ this . mountProcess = GVFSPlatform . Instance . StartBackgroundVFS4GProcess (
233263 tracer ,
234264 mountExecutableLocation ,
235265 new [ ]
0 commit comments