Created
October 13, 2020 23:47
-
-
Save gammazero/6de3265ef5e0d1b36d613ca7c8571602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"path" | |
"syscall" | |
) | |
// isMountPoint returns true if the given directory is a mountpoint | |
func isMountPoint(fileName string) (bool, error) { | |
dir := path.Clean(fileName) | |
if dir == "/" { | |
return true, nil | |
} | |
var stDir, stParent syscall.Stat_t | |
err := syscall.Stat(dir, &stDir) | |
if err != nil { | |
return false, err | |
} | |
err = syscall.Stat(path.Dir(dir), &stParent) | |
if err != nil { | |
return false, err | |
} | |
return stDir.Dev != stParent.Dev, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment