55 "log"
66 "os"
77 "os/signal"
8+ "path/filepath"
9+ "strings"
810
911 "bazil.org/fuse"
1012 "bazil.org/fuse/fs"
@@ -29,13 +31,45 @@ MOUNTPOINT is the directory where the filesystem will be mounted.`,
2931 }
3032}
3133
34+ // pathsOverlap checks if two paths overlap (one contains the other).
35+ // It returns true if either path is a parent/child of the other.
36+ func pathsOverlap (path1 , path2 string ) bool {
37+ // Convert to absolute paths and clean them
38+ abs1 , err1 := filepath .Abs (path1 )
39+ abs2 , err2 := filepath .Abs (path2 )
40+
41+ // If we can't resolve absolute paths, compare as-is
42+ if err1 != nil {
43+ abs1 = filepath .Clean (path1 )
44+ }
45+ if err2 != nil {
46+ abs2 = filepath .Clean (path2 )
47+ }
48+
49+ // Ensure paths end with separator for accurate prefix checking
50+ if ! strings .HasSuffix (abs1 , string (filepath .Separator )) {
51+ abs1 += string (filepath .Separator )
52+ }
53+ if ! strings .HasSuffix (abs2 , string (filepath .Separator )) {
54+ abs2 += string (filepath .Separator )
55+ }
56+
57+ // Check if either path is a prefix of the other
58+ return strings .HasPrefix (abs1 , abs2 ) || strings .HasPrefix (abs2 , abs1 )
59+ }
60+
3261func runMount (cmd * cobra.Command , args []string ) {
3362 // Print version info on startup
3463 fmt .Printf ("djafs %s starting...\n " , version .GetFullVersion ())
3564
3665 storagePath := args [0 ]
3766 mountpoint := args [1 ]
3867
68+ // Validate that storage path and mountpoint don't overlap
69+ if pathsOverlap (storagePath , mountpoint ) {
70+ log .Fatalf ("Storage path and mountpoint cannot overlap: storage=%s, mount=%s" , storagePath , mountpoint )
71+ }
72+
3973 // Ensure storage directory exists
4074 if err := os .MkdirAll (storagePath , 0755 ); err != nil {
4175 log .Fatalf ("Failed to create storage directory: %v" , err )
0 commit comments