66 "fmt"
77 "io"
88 "os"
9- filepath "path"
9+ "path"
1010 walkpath "path/filepath"
1111 "sort"
1212 "strings"
@@ -367,7 +367,7 @@ var errInvalidIno = errors.New("invalid ino")
367367func inoToPath (ino uint64 ) string {
368368 hex := fmt .Sprintf ("%016x" , ino )
369369 // Create subdirectory structure: /01/0123456789abcdef
370- return filepath .Join ("/" , hex [:2 ], hex )
370+ return path .Join ("/" , hex [:2 ], hex )
371371}
372372
373373// loadInode - loads the iNode defined by `ino` or returns an error
@@ -396,16 +396,16 @@ func (fs *FileSystem) saveData(ino uint64, data []byte) error {
396396
397397 // Use external content filesystem if available, otherwise fall back to BoltDB data bucket
398398 if fs .contentFS != nil {
399- path := inoToPath (ino )
399+ contentPath := inoToPath (ino )
400400
401401 // Ensure parent directory exists
402- dir := filepath .Dir (path )
402+ dir := path .Dir (contentPath )
403403 if err := fs .contentFS .MkdirAll (dir , 0755 ); err != nil {
404404 return fmt .Errorf ("failed to create directory: %w" , err )
405405 }
406406
407407 // Write file atomically
408- f , err := fs .contentFS .OpenFile (path , os .O_CREATE | os .O_WRONLY | os .O_TRUNC , 0644 )
408+ f , err := fs .contentFS .OpenFile (contentPath , os .O_CREATE | os .O_WRONLY | os .O_TRUNC , 0644 )
409409 if err != nil {
410410 return fmt .Errorf ("failed to create file: %w" , err )
411411 }
@@ -435,9 +435,9 @@ func (fs *FileSystem) loadData(ino uint64) ([]byte, error) {
435435
436436 // Use external content filesystem if available, otherwise fall back to BoltDB data bucket
437437 if fs .contentFS != nil {
438- path := inoToPath (ino )
438+ contentPath := inoToPath (ino )
439439
440- f , err := fs .contentFS .OpenFile (path , os .O_RDONLY , 0 )
440+ f , err := fs .contentFS .OpenFile (contentPath , os .O_RDONLY , 0 )
441441 if err != nil {
442442 if os .IsNotExist (err ) {
443443 return []byte {}, nil
@@ -478,12 +478,12 @@ func (fs *FileSystem) loadData(ino uint64) ([]byte, error) {
478478// cleanPath - takes the absolute or relative path provided by `name` and
479479// returns the directory and filename of the cleand absolute path.
480480func (fs * FileSystem ) cleanPath (name string ) (string , string ) {
481- path := name
482- if ! filepath .IsAbs (path ) {
483- path = filepath .Join (fs .cwd , path )
481+ p := name
482+ if ! path .IsAbs (p ) {
483+ p = path .Join (fs .cwd , p )
484484 }
485- dir , filename := filepath .Split (path )
486- dir = filepath .Clean (dir )
485+ dir , filename := path .Split (p )
486+ dir = path .Clean (dir )
487487 return dir , filename
488488}
489489
@@ -520,12 +520,12 @@ func (fs *FileSystem) Rename(oldpath, newpath string) error {
520520 }
521521 if srcChild == nil {
522522 linkErr .Err = os .ErrNotExist
523- linkErr .Old = filepath .Join (srcDir , srcFilename )
523+ linkErr .Old = path .Join (srcDir , srcFilename )
524524 return linkErr
525525 }
526526 if dstChild != nil {
527527 linkErr .Err = os .ErrExist
528- linkErr .New = filepath .Join (dstDir , dstFilename )
528+ linkErr .New = path .Join (dstDir , dstFilename )
529529 return linkErr
530530 }
531531
@@ -580,12 +580,12 @@ func (fs *FileSystem) Copy(source, destination string) error {
580580 }
581581 if srcChild == nil {
582582 pathErr .Err = os .ErrNotExist
583- pathErr .Path = filepath .Join (srcDir , srcFilename )
583+ pathErr .Path = path .Join (srcDir , srcFilename )
584584 return pathErr
585585 }
586586 if dstChild != nil {
587587 pathErr .Err = os .ErrExist
588- pathErr .Path = filepath .Join (dstDir , dstFilename )
588+ pathErr .Path = path .Join (dstDir , dstFilename )
589589 return pathErr
590590 }
591591
@@ -627,7 +627,7 @@ func (fs *FileSystem) Chdir(name string) error {
627627 if err != nil {
628628 return err
629629 }
630- fs .cwd = filepath .Join (dir , filename )
630+ fs .cwd = path .Join (dir , filename )
631631 return nil
632632}
633633
@@ -771,7 +771,7 @@ func (fs *FileSystem) OpenFile(name string, flag int, perm os.FileMode) (absfs.F
771771func (fs * FileSystem ) Stat (name string ) (os.FileInfo , error ) {
772772
773773 dir , filename := fs .cleanPath (name )
774- node , err := fs .resolve (filepath .Join (dir , filename ))
774+ node , err := fs .resolve (path .Join (dir , filename ))
775775 if err != nil {
776776 return nil , err
777777 }
@@ -800,8 +800,8 @@ func (fs *FileSystem) Stat(name string) (os.FileInfo, error) {
800800 return nil , err
801801 }
802802
803- if ! filepath .IsAbs (link ) {
804- link = filepath .Join (name , link )
803+ if ! path .IsAbs (link ) {
804+ link = path .Join (name , link )
805805 }
806806
807807 return fs .Stat (link )
@@ -811,18 +811,18 @@ func (fs *FileSystem) Stat(name string) (os.FileInfo, error) {
811811// there is an error, it will be of type *os.PathError.
812812func (fs * FileSystem ) Truncate (name string , size int64 ) error {
813813 dir , filename := fs .cleanPath (name )
814- path := filepath .Join (dir , filename )
815- node , err := fs .resolve (path )
814+ p := path .Join (dir , filename )
815+ node , err := fs .resolve (p )
816816 if err != nil {
817817 if err != os .ErrNotExist {
818818 return err
819819 }
820- f , err := fs .Create (path )
820+ f , err := fs .Create (p )
821821 if err != nil {
822822 return err
823823 }
824824 f .Close ()
825- node , err = fs .resolve (path )
825+ node , err = fs .resolve (p )
826826 if err != nil {
827827 return err
828828 }
@@ -931,8 +931,8 @@ func (fs *FileSystem) saveParentChild(parent *iNode, filename string, child *iNo
931931func (fs * FileSystem ) deleteInode (ino uint64 ) error {
932932 // Delete from external content filesystem first
933933 if fs .contentFS != nil {
934- path := inoToPath (ino )
935- if err := fs .contentFS .Remove (path ); err != nil && ! os .IsNotExist (err ) {
934+ contentPath := inoToPath (ino )
935+ if err := fs .contentFS .Remove (contentPath ); err != nil && ! os .IsNotExist (err ) {
936936 return err
937937 }
938938 }
@@ -990,12 +990,12 @@ func (fs *FileSystem) Mkdir(name string, perm os.FileMode) error {
990990// a directory, MkdirAll does nothing and returns nil.
991991func (fs * FileSystem ) MkdirAll (name string , perm os.FileMode ) error {
992992 dir , filename := fs .cleanPath (name )
993- name = strings .TrimLeft (filepath .Join (dir , filename ), "/" )
993+ name = strings .TrimLeft (path .Join (dir , filename ), "/" )
994994
995- path := "/"
996- for _ , p := range strings .Split (name , "/" ) {
997- path = filepath .Join (path , p )
998- err := fs .Mkdir (path , perm )
995+ p := "/"
996+ for _ , part := range strings .Split (name , "/" ) {
997+ p = path .Join (p , part )
998+ err := fs .Mkdir (p , perm )
999999
10001000 if err != nil {
10011001 patherr := err .(* os.PathError )
@@ -1061,7 +1061,7 @@ func (fs *FileSystem) Walk(root string, fn func(string, os.FileInfo, error) erro
10611061
10621062 dir , filename := fs .cleanPath (root )
10631063 parent , node := fs .loadParentChild (dir , filename )
1064- root = filepath .Join (dir , filename )
1064+ root = path .Join (dir , filename )
10651065 if node == nil {
10661066 node = parent
10671067 }
@@ -1079,11 +1079,11 @@ func (fs *FileSystem) Walk(root string, fn func(string, os.FileInfo, error) erro
10791079 return err
10801080 }
10811081
1082- recurse = func (path string , ino uint64 ) error {
1082+ recurse = func (p string , ino uint64 ) error {
10831083 node := new (iNode )
10841084 err := decodeNode (b .inodes , ino , node )
10851085
1086- err = fn (path , inodeinfo {filepath .Base (path ), node }, err )
1086+ err = fn (p , inodeinfo {path .Base (p ), node }, err )
10871087
10881088 if err != nil {
10891089 if err == walkpath .SkipDir {
@@ -1096,7 +1096,7 @@ func (fs *FileSystem) Walk(root string, fn func(string, os.FileInfo, error) erro
10961096 }
10971097
10981098 for _ , child := range node .Children {
1099- err := recurse (filepath .Join (path , child .Name ), child .Ino )
1099+ err := recurse (path .Join (p , child .Name ), child .Ino )
11001100 if err != nil {
11011101 return err
11021102 }
@@ -1120,7 +1120,7 @@ func (fs *FileSystem) Walk(root string, fn func(string, os.FileInfo, error) erro
11201120func (fs * FileSystem ) FastWalk (root string , fn func (string , os.FileMode ) error ) error {
11211121 dir , filename := fs .cleanPath (root )
11221122 parent , node := fs .loadParentChild (dir , filename )
1123- root = filepath .Join (dir , filename )
1123+ root = path .Join (dir , filename )
11241124 if node == nil {
11251125 node = parent
11261126 }
@@ -1138,13 +1138,13 @@ func (fs *FileSystem) FastWalk(root string, fn func(string, os.FileMode) error)
11381138 return err
11391139 }
11401140
1141- recurse = func (path string , ino uint64 ) error {
1141+ recurse = func (p string , ino uint64 ) error {
11421142 node , err := b .GetInode (ino )
11431143 if err != nil {
11441144 return err
11451145 }
11461146
1147- err = fn (path , node .Mode )
1147+ err = fn (p , node .Mode )
11481148 if err != nil {
11491149 if err == walkpath .SkipDir {
11501150 return nil
@@ -1154,7 +1154,7 @@ func (fs *FileSystem) FastWalk(root string, fn func(string, os.FileMode) error)
11541154
11551155 // Traverse children without sorting (faster)
11561156 for _ , child := range node .Children {
1157- err := recurse (filepath .Join (path , child .Name ), child .Ino )
1157+ err := recurse (path .Join (p , child .Name ), child .Ino )
11581158 if err != nil {
11591159 return err
11601160 }
@@ -1180,7 +1180,7 @@ func (fs *FileSystem) RemoveAll(name string) error {
11801180 rootid = parent .Ino
11811181 }
11821182
1183- err := fs .Walk (filepath .Join (dir , filename ), func (path string , info os.FileInfo , err error ) error {
1183+ err := fs .Walk (path .Join (dir , filename ), func (p string , info os.FileInfo , err error ) error {
11841184 node , ok := info .Sys ().(* iNode )
11851185 if ! ok {
11861186 return errors .New ("unable to cast os.FileInfo to *iNode" )
@@ -1225,8 +1225,8 @@ func (fs *FileSystem) RemoveAll(name string) error {
12251225
12261226 if fs .contentFS != nil {
12271227 for _ , ino := range fileInos {
1228- path := inoToPath (ino )
1229- if err := fs .contentFS .Remove (path ); err != nil && ! os .IsNotExist (err ) {
1228+ contentPath := inoToPath (ino )
1229+ if err := fs .contentFS .Remove (contentPath ); err != nil && ! os .IsNotExist (err ) {
12301230 return err
12311231 }
12321232 }
@@ -1340,8 +1340,8 @@ func (fs *FileSystem) Chown(name string, uid, gid int) error {
13401340 if err != nil {
13411341 return err
13421342 }
1343- if ! filepath .IsAbs (link ) {
1344- link = filepath .Join (name , link )
1343+ if ! path .IsAbs (link ) {
1344+ link = path .Join (name , link )
13451345 }
13461346
13471347 return fs .Chown (link , uid , gid )
@@ -1368,7 +1368,7 @@ func (fs *FileSystem) Chmod(name string, mode os.FileMode) error {
13681368func (fs * FileSystem ) Lstat (name string ) (os.FileInfo , error ) {
13691369 pathErr := & os.PathError {Op : "lstat" , Path : name }
13701370 dir , filename := fs .cleanPath (name )
1371- node , err := fs .resolve (filepath .Join (dir , filename ))
1371+ node , err := fs .resolve (path .Join (dir , filename ))
13721372 if err != nil {
13731373 pathErr .Err = err
13741374 return nil , pathErr
0 commit comments