@@ -2,7 +2,6 @@ package volume
22
33import  (
44	"fmt" 
5- 	"os" 
65	"path/filepath" 
76	"regexp" 
87	"strings" 
@@ -291,7 +290,7 @@ func (VolumeAPI) GetVolumeIDFromTargetPath(mount string) (string, error) {
291290}
292291
293292func  getTarget (mount  string ) (string , error ) {
294- 	mountedFolder , err  :=  isMountedFolder (mount )
293+ 	mountedFolder , err  :=  utils . IsMountedFolder (mount )
295294	if  err  !=  nil  {
296295		return  "" , err 
297296	}
@@ -347,15 +346,13 @@ func findClosestVolume(path string) (string, error) {
347346	// The number of iterations is 256, which is similar to the number of iterations in filepath-securejoin 
348347	// https://github.com/cyphar/filepath-securejoin/blob/64536a8a66ae59588c981e2199f1dcf410508e07/join.go#L51 
349348	for  i  :=  0 ; i  <  256 ; i  +=  1  {
350- 		fi , err  :=  os . Lstat (candidatePath )
349+ 		isSymlink , err  :=  utils . IsPathSymlink (candidatePath )
351350		if  err  !=  nil  {
352351			return  "" , err 
353352		}
354- 		// for windows NTFS, check if the path is symlink instead of directory. 
355- 		isSymlink  :=  fi .Mode ()& os .ModeSymlink  !=  0  ||  fi .Mode ()& os .ModeIrregular  !=  0 
356353
357354		// mounted folder created by SetVolumeMountPoint may still report ModeSymlink == 0 
358- 		mountedFolder , err  :=  isMountedFolder (candidatePath )
355+ 		mountedFolder , err  :=  utils . IsMountedFolder (candidatePath )
359356		if  err  !=  nil  {
360357			return  "" , err 
361358		}
@@ -392,39 +389,6 @@ func findClosestVolume(path string) (string, error) {
392389	return  "" , fmt .Errorf ("failed to find the closest volume for path=%s" , path )
393390}
394391
395- // isMountedFolder checks whether the `path` is a mounted folder. 
396- func  isMountedFolder (path  string ) (bool , error ) {
397- 	// https://learn.microsoft.com/en-us/windows/win32/fileio/determining-whether-a-directory-is-a-volume-mount-point 
398- 	utf16Path , _  :=  windows .UTF16PtrFromString (path )
399- 	attrs , err  :=  windows .GetFileAttributes (utf16Path )
400- 	if  err  !=  nil  {
401- 		return  false , err 
402- 	}
403- 
404- 	if  (attrs  &  windows .FILE_ATTRIBUTE_REPARSE_POINT ) ==  0  {
405- 		return  false , nil 
406- 	}
407- 
408- 	var  findData  windows.Win32finddata 
409- 	findHandle , err  :=  windows .FindFirstFile (utf16Path , & findData )
410- 	if  err  !=  nil  &&  ! errors .Is (err , windows .ERROR_NO_MORE_FILES ) {
411- 		return  false , err 
412- 	}
413- 
414- 	for  err  ==  nil  {
415- 		if  findData .Reserved0 & windows .IO_REPARSE_TAG_MOUNT_POINT  !=  0  {
416- 			return  true , nil 
417- 		}
418- 
419- 		err  =  windows .FindNextFile (findHandle , & findData )
420- 		if  err  !=  nil  &&  ! errors .Is (err , windows .ERROR_NO_MORE_FILES ) {
421- 			return  false , err 
422- 		}
423- 	}
424- 
425- 	return  false , nil 
426- }
427- 
428392// getVolumeForDriveLetter gets a volume from a drive letter (e.g. C:/). 
429393func  getVolumeForDriveLetter (path  string ) (string , error ) {
430394	if  len (path ) !=  1  {
0 commit comments