File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -376,15 +376,26 @@ private async Task PrepareUserForSftp(string username)
376
376
377
377
var directoryInfo = new DirectoryInfo ( dirPath ) ;
378
378
379
- var firstParentInChroot = directoryInfo . Parent ?? chrootDirectory ;
380
- while ( ( firstParentInChroot . Parent ??
381
- throw new InvalidOperationException ( "Cannot find first parent in chroot" ) ) . FullName !=
382
- chrootDirectory . FullName )
379
+ try
383
380
{
384
- firstParentInChroot = firstParentInChroot . Parent ;
381
+ var firstParentInChroot = directoryInfo ;
382
+ while ( ( firstParentInChroot . Parent ??
383
+ throw new InvalidOperationException ( "Cannot find first parent in chroot" ) ) . FullName !=
384
+ chrootDirectory . FullName )
385
+ {
386
+ firstParentInChroot = firstParentInChroot . Parent ;
387
+ }
388
+ await ProcessUtil . QuickRun ( "chown" , $ "-R { username } :{ SftpUserInventoryGroup } { firstParentInChroot . FullName } ") ;
389
+ }
390
+ catch ( Exception exception )
391
+ {
392
+ _logger . LogWarning ( exception ,
393
+ "Could not determine first parent of '{dir}' in chroot '{chroot}' or failed to set permissions" ,
394
+ directoryInfo . FullName , chrootDirectory . FullName ) ;
395
+
396
+ await ProcessUtil . QuickRun ( "chown" , $ "-R { username } :{ SftpUserInventoryGroup } { directoryInfo . FullName } ") ;
385
397
}
386
398
387
- await ProcessUtil . QuickRun ( "chown" , $ "-R { username } :{ SftpUserInventoryGroup } { firstParentInChroot . FullName } ") ;
388
399
}
389
400
390
401
var sshDir = Path . Combine ( homeDirPath , ".ssh" ) ;
You can’t perform that action at this time.
0 commit comments