You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
17 KiB

7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
5 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
  1. package filesys
  2. import (
  3. "bytes"
  4. "context"
  5. "math"
  6. "os"
  7. "strings"
  8. "syscall"
  9. "time"
  10. "github.com/seaweedfs/fuse"
  11. "github.com/seaweedfs/fuse/fs"
  12. "github.com/chrislusf/seaweedfs/weed/filer"
  13. "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
  14. "github.com/chrislusf/seaweedfs/weed/glog"
  15. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  16. "github.com/chrislusf/seaweedfs/weed/util"
  17. )
  18. type Dir struct {
  19. name string
  20. wfs *WFS
  21. entry *filer_pb.Entry
  22. parent *Dir
  23. id uint64
  24. }
  25. var _ = fs.Node(&Dir{})
  26. var _ = fs.NodeIdentifier(&Dir{})
  27. var _ = fs.NodeCreater(&Dir{})
  28. var _ = fs.NodeMknoder(&Dir{})
  29. var _ = fs.NodeMkdirer(&Dir{})
  30. var _ = fs.NodeFsyncer(&Dir{})
  31. var _ = fs.NodeRequestLookuper(&Dir{})
  32. var _ = fs.HandleReadDirAller(&Dir{})
  33. var _ = fs.NodeRemover(&Dir{})
  34. var _ = fs.NodeRenamer(&Dir{})
  35. var _ = fs.NodeSetattrer(&Dir{})
  36. var _ = fs.NodeGetxattrer(&Dir{})
  37. var _ = fs.NodeSetxattrer(&Dir{})
  38. var _ = fs.NodeRemovexattrer(&Dir{})
  39. var _ = fs.NodeListxattrer(&Dir{})
  40. var _ = fs.NodeForgetter(&Dir{})
  41. func (dir *Dir) Id() uint64 {
  42. if dir.parent == nil {
  43. return 1
  44. }
  45. return dir.id
  46. }
  47. func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error {
  48. entry, err := dir.maybeLoadEntry()
  49. if err != nil {
  50. glog.V(3).Infof("dir Attr %s, err: %+v", dir.FullPath(), err)
  51. return err
  52. }
  53. // https://github.com/bazil/fuse/issues/196
  54. attr.Valid = time.Second
  55. attr.Inode = dir.Id()
  56. attr.Mode = os.FileMode(entry.Attributes.FileMode) | os.ModeDir
  57. attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)
  58. attr.Crtime = time.Unix(entry.Attributes.Crtime, 0)
  59. attr.Ctime = time.Unix(entry.Attributes.Mtime, 0)
  60. attr.Atime = time.Unix(entry.Attributes.Mtime, 0)
  61. attr.Gid = entry.Attributes.Gid
  62. attr.Uid = entry.Attributes.Uid
  63. if dir.FullPath() == dir.wfs.option.FilerMountRootPath {
  64. attr.BlockSize = blockSize
  65. }
  66. glog.V(4).Infof("dir Attr %s, attr: %+v", dir.FullPath(), attr)
  67. return nil
  68. }
  69. func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
  70. glog.V(4).Infof("dir Getxattr %s", dir.FullPath())
  71. entry, err := dir.maybeLoadEntry()
  72. if err != nil {
  73. return err
  74. }
  75. return getxattr(entry, req, resp)
  76. }
  77. func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
  78. // fsync works at OS level
  79. // write the file chunks to the filerGrpcAddress
  80. glog.V(3).Infof("dir %s fsync %+v", dir.FullPath(), req)
  81. return nil
  82. }
  83. func (dir *Dir) newFile(name string, fileMode os.FileMode) fs.Node {
  84. fileFullPath := util.NewFullPath(dir.FullPath(), name)
  85. fileId := fileFullPath.AsInode(fileMode)
  86. dir.wfs.handlesLock.Lock()
  87. existingHandle, found := dir.wfs.handles[fileId]
  88. dir.wfs.handlesLock.Unlock()
  89. if found {
  90. glog.V(4).Infof("newFile found opened file handle: %+v", fileFullPath)
  91. return existingHandle.f
  92. }
  93. return &File{
  94. Name: name,
  95. dir: dir,
  96. wfs: dir.wfs,
  97. id: fileId,
  98. }
  99. }
  100. func (dir *Dir) newDirectory(fullpath util.FullPath) fs.Node {
  101. return &Dir{name: fullpath.Name(), wfs: dir.wfs, parent: dir, id: fullpath.AsInode(os.ModeDir)}
  102. }
  103. func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
  104. resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
  105. if err := checkName(req.Name); err != nil {
  106. return nil, nil, err
  107. }
  108. exclusive := req.Flags&fuse.OpenExclusive != 0
  109. isDirectory := req.Mode&os.ModeDir > 0
  110. if exclusive || isDirectory {
  111. _, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, exclusive)
  112. if err != nil {
  113. return nil, nil, err
  114. }
  115. }
  116. var node fs.Node
  117. if isDirectory {
  118. node = dir.newDirectory(util.NewFullPath(dir.FullPath(), req.Name))
  119. return node, node, nil
  120. }
  121. node = dir.newFile(req.Name, req.Mode)
  122. file := node.(*File)
  123. file.entry = &filer_pb.Entry{
  124. Name: req.Name,
  125. IsDirectory: req.Mode&os.ModeDir > 0,
  126. Attributes: &filer_pb.FuseAttributes{
  127. Mtime: time.Now().Unix(),
  128. Crtime: time.Now().Unix(),
  129. FileMode: uint32(req.Mode &^ dir.wfs.option.Umask),
  130. Uid: req.Uid,
  131. Gid: req.Gid,
  132. Collection: dir.wfs.option.Collection,
  133. Replication: dir.wfs.option.Replication,
  134. TtlSec: dir.wfs.option.TtlSec,
  135. },
  136. }
  137. file.dirtyMetadata = true
  138. fh := dir.wfs.AcquireHandle(file, req.Uid, req.Gid)
  139. return file, fh, nil
  140. }
  141. func (dir *Dir) Mknod(ctx context.Context, req *fuse.MknodRequest) (fs.Node, error) {
  142. if err := checkName(req.Name); err != nil {
  143. return nil, err
  144. }
  145. glog.V(3).Infof("dir %s Mknod %+v", dir.FullPath(), req)
  146. _, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, false)
  147. if err != nil {
  148. return nil, err
  149. }
  150. var node fs.Node
  151. node = dir.newFile(req.Name, req.Mode)
  152. return node, nil
  153. }
  154. func (dir *Dir) doCreateEntry(name string, mode os.FileMode, uid, gid uint32, exclusive bool) (*filer_pb.CreateEntryRequest, error) {
  155. dirFullPath := dir.FullPath()
  156. request := &filer_pb.CreateEntryRequest{
  157. Directory: dirFullPath,
  158. Entry: &filer_pb.Entry{
  159. Name: name,
  160. IsDirectory: mode&os.ModeDir > 0,
  161. Attributes: &filer_pb.FuseAttributes{
  162. Mtime: time.Now().Unix(),
  163. Crtime: time.Now().Unix(),
  164. FileMode: uint32(mode &^ dir.wfs.option.Umask),
  165. Uid: uid,
  166. Gid: gid,
  167. Collection: dir.wfs.option.Collection,
  168. Replication: dir.wfs.option.Replication,
  169. TtlSec: dir.wfs.option.TtlSec,
  170. },
  171. },
  172. OExcl: exclusive,
  173. Signatures: []int32{dir.wfs.signature},
  174. }
  175. glog.V(1).Infof("create %s/%s", dirFullPath, name)
  176. err := dir.wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  177. dir.wfs.mapPbIdFromLocalToFiler(request.Entry)
  178. defer dir.wfs.mapPbIdFromFilerToLocal(request.Entry)
  179. if err := filer_pb.CreateEntry(client, request); err != nil {
  180. if strings.Contains(err.Error(), "EEXIST") {
  181. return fuse.EEXIST
  182. }
  183. glog.V(0).Infof("create %s/%s: %v", dirFullPath, name, err)
  184. return fuse.EIO
  185. }
  186. if err := dir.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  187. glog.Errorf("local InsertEntry dir %s/%s: %v", dirFullPath, name, err)
  188. return fuse.EIO
  189. }
  190. return nil
  191. })
  192. return request, err
  193. }
  194. func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
  195. if err := checkName(req.Name); err != nil {
  196. return nil, err
  197. }
  198. glog.V(4).Infof("mkdir %s: %s", dir.FullPath(), req.Name)
  199. newEntry := &filer_pb.Entry{
  200. Name: req.Name,
  201. IsDirectory: true,
  202. Attributes: &filer_pb.FuseAttributes{
  203. Mtime: time.Now().Unix(),
  204. Crtime: time.Now().Unix(),
  205. FileMode: uint32(req.Mode &^ dir.wfs.option.Umask),
  206. Uid: req.Uid,
  207. Gid: req.Gid,
  208. },
  209. }
  210. dirFullPath := dir.FullPath()
  211. err := dir.wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  212. dir.wfs.mapPbIdFromLocalToFiler(newEntry)
  213. defer dir.wfs.mapPbIdFromFilerToLocal(newEntry)
  214. request := &filer_pb.CreateEntryRequest{
  215. Directory: dirFullPath,
  216. Entry: newEntry,
  217. Signatures: []int32{dir.wfs.signature},
  218. }
  219. glog.V(1).Infof("mkdir: %v", request)
  220. if err := filer_pb.CreateEntry(client, request); err != nil {
  221. glog.V(0).Infof("mkdir %s/%s: %v", dirFullPath, req.Name, err)
  222. return err
  223. }
  224. if err := dir.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  225. glog.Errorf("local mkdir dir %s/%s: %v", dirFullPath, req.Name, err)
  226. return fuse.EIO
  227. }
  228. return nil
  229. })
  230. if err == nil {
  231. node := dir.newDirectory(util.NewFullPath(dirFullPath, req.Name))
  232. return node, nil
  233. }
  234. glog.V(0).Infof("mkdir %s/%s: %v", dirFullPath, req.Name, err)
  235. return nil, fuse.EIO
  236. }
  237. func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) {
  238. if err := checkName(req.Name); err != nil {
  239. return nil, err
  240. }
  241. dirPath := util.FullPath(dir.FullPath())
  242. // glog.V(4).Infof("dir Lookup %s: %s by %s", dirPath, req.Name, req.Header.String())
  243. fullFilePath := dirPath.Child(req.Name)
  244. visitErr := meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, dirPath)
  245. if visitErr != nil {
  246. glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
  247. return nil, fuse.EIO
  248. }
  249. localEntry, cacheErr := dir.wfs.metaCache.FindEntry(context.Background(), fullFilePath)
  250. if cacheErr == filer_pb.ErrNotFound {
  251. return nil, fuse.ENOENT
  252. }
  253. if localEntry == nil {
  254. // glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath)
  255. entry, err := filer_pb.GetEntry(dir.wfs, fullFilePath)
  256. if err != nil {
  257. glog.V(1).Infof("dir GetEntry %s: %v", fullFilePath, err)
  258. return nil, fuse.ENOENT
  259. }
  260. localEntry = filer.FromPbEntry(string(dirPath), entry)
  261. } else {
  262. glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath)
  263. }
  264. if localEntry != nil {
  265. if localEntry.IsDirectory() {
  266. node = dir.newDirectory(fullFilePath)
  267. } else {
  268. node = dir.newFile(req.Name, localEntry.Attr.Mode)
  269. }
  270. // resp.EntryValid = time.Second
  271. resp.Attr.Valid = time.Second
  272. resp.Attr.Size = localEntry.FileSize
  273. resp.Attr.Mtime = localEntry.Attr.Mtime
  274. resp.Attr.Crtime = localEntry.Attr.Crtime
  275. resp.Attr.Mode = localEntry.Attr.Mode
  276. resp.Attr.Gid = localEntry.Attr.Gid
  277. resp.Attr.Uid = localEntry.Attr.Uid
  278. if localEntry.HardLinkCounter > 0 {
  279. resp.Attr.Nlink = uint32(localEntry.HardLinkCounter)
  280. }
  281. return node, nil
  282. }
  283. glog.V(4).Infof("not found dir GetEntry %s: %v", fullFilePath, err)
  284. return nil, fuse.ENOENT
  285. }
  286. func (dir *Dir) ReadDirAll(ctx context.Context) (ret []fuse.Dirent, err error) {
  287. dirPath := util.FullPath(dir.FullPath())
  288. glog.V(4).Infof("dir ReadDirAll %s", dirPath)
  289. processEachEntryFn := func(entry *filer.Entry, isLast bool) {
  290. if entry.IsDirectory() {
  291. dirent := fuse.Dirent{Name: entry.Name(), Type: fuse.DT_Dir, Inode: dirPath.Child(entry.Name()).AsInode(os.ModeDir)}
  292. ret = append(ret, dirent)
  293. } else {
  294. dirent := fuse.Dirent{Name: entry.Name(), Type: findFileType(uint16(entry.Attr.Mode)), Inode: dirPath.Child(entry.Name()).AsInode(entry.Attr.Mode)}
  295. ret = append(ret, dirent)
  296. }
  297. }
  298. if err = meta_cache.EnsureVisited(dir.wfs.metaCache, dir.wfs, dirPath); err != nil {
  299. glog.Errorf("dir ReadDirAll %s: %v", dirPath, err)
  300. return nil, fuse.EIO
  301. }
  302. listErr := dir.wfs.metaCache.ListDirectoryEntries(context.Background(), dirPath, "", false, int64(math.MaxInt32), func(entry *filer.Entry) bool {
  303. processEachEntryFn(entry, false)
  304. return true
  305. })
  306. if listErr != nil {
  307. glog.Errorf("list meta cache: %v", listErr)
  308. return nil, fuse.EIO
  309. }
  310. // create proper . and .. directories
  311. ret = append(ret, fuse.Dirent{
  312. Inode: dirPath.AsInode(os.ModeDir),
  313. Name: ".",
  314. Type: fuse.DT_Dir,
  315. })
  316. // return the correct parent inode for the mount root
  317. var inode uint64
  318. if string(dirPath) == dir.wfs.option.FilerMountRootPath {
  319. inode = dir.wfs.option.MountParentInode
  320. } else {
  321. inode = util.FullPath(dir.parent.FullPath()).AsInode(os.ModeDir)
  322. }
  323. ret = append(ret, fuse.Dirent{
  324. Inode: inode,
  325. Name: "..",
  326. Type: fuse.DT_Dir,
  327. })
  328. return
  329. }
  330. func findFileType(mode uint16) fuse.DirentType {
  331. switch mode & (syscall.S_IFMT & 0xffff) {
  332. case syscall.S_IFSOCK:
  333. return fuse.DT_Socket
  334. case syscall.S_IFLNK:
  335. return fuse.DT_Link
  336. case syscall.S_IFREG:
  337. return fuse.DT_File
  338. case syscall.S_IFBLK:
  339. return fuse.DT_Block
  340. case syscall.S_IFDIR:
  341. return fuse.DT_Dir
  342. case syscall.S_IFCHR:
  343. return fuse.DT_Char
  344. case syscall.S_IFIFO:
  345. return fuse.DT_FIFO
  346. }
  347. return fuse.DT_File
  348. }
  349. func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
  350. parentHasPermission := false
  351. parentEntry, err := dir.maybeLoadEntry()
  352. if err != nil {
  353. return err
  354. }
  355. if err := checkPermission(parentEntry, req.Uid, req.Gid, true); err == nil {
  356. parentHasPermission = true
  357. }
  358. dirFullPath := dir.FullPath()
  359. filePath := util.NewFullPath(dirFullPath, req.Name)
  360. entry, err := filer_pb.GetEntry(dir.wfs, filePath)
  361. if err != nil {
  362. return err
  363. }
  364. if !parentHasPermission {
  365. if err := checkPermission(entry, req.Uid, req.Gid, true); err != nil {
  366. return err
  367. }
  368. }
  369. if !req.Dir {
  370. return dir.removeOneFile(entry, req)
  371. }
  372. return dir.removeFolder(entry, req)
  373. }
  374. func (dir *Dir) removeOneFile(entry *filer_pb.Entry, req *fuse.RemoveRequest) error {
  375. dirFullPath := dir.FullPath()
  376. filePath := util.NewFullPath(dirFullPath, req.Name)
  377. // first, ensure the filer store can correctly delete
  378. glog.V(3).Infof("remove file: %v", req)
  379. isDeleteData := entry != nil && entry.HardLinkCounter <= 1
  380. err := filer_pb.Remove(dir.wfs, dirFullPath, req.Name, isDeleteData, false, false, false, []int32{dir.wfs.signature})
  381. if err != nil {
  382. glog.V(3).Infof("not found remove file %s: %v", filePath, err)
  383. return fuse.ENOENT
  384. }
  385. // then, delete meta cache and fsNode cache
  386. if err = dir.wfs.metaCache.DeleteEntry(context.Background(), filePath); err != nil {
  387. glog.V(3).Infof("local DeleteEntry %s: %v", filePath, err)
  388. return fuse.ESTALE
  389. }
  390. // remove current file handle if any
  391. dir.wfs.handlesLock.Lock()
  392. defer dir.wfs.handlesLock.Unlock()
  393. inodeId := filePath.AsInode(0)
  394. if fh, ok := dir.wfs.handles[inodeId]; ok {
  395. delete(dir.wfs.handles, inodeId)
  396. fh.isDeleted = true
  397. }
  398. return nil
  399. }
  400. func (dir *Dir) removeFolder(entry *filer_pb.Entry, req *fuse.RemoveRequest) error {
  401. dirFullPath := dir.FullPath()
  402. glog.V(3).Infof("remove directory entry: %v", req)
  403. ignoreRecursiveErr := true // ignore recursion error since the OS should manage it
  404. err := filer_pb.Remove(dir.wfs, dirFullPath, req.Name, true, true, ignoreRecursiveErr, false, []int32{dir.wfs.signature})
  405. if err != nil {
  406. glog.V(0).Infof("remove %s/%s: %v", dirFullPath, req.Name, err)
  407. if strings.Contains(err.Error(), filer.MsgFailDelNonEmptyFolder) {
  408. return fuse.EEXIST
  409. }
  410. return fuse.ENOENT
  411. }
  412. t := util.NewFullPath(dirFullPath, req.Name)
  413. dir.wfs.metaCache.DeleteEntry(context.Background(), t)
  414. return nil
  415. }
  416. func (dir *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
  417. glog.V(4).Infof("%v dir setattr %+v mode=%d", dir.FullPath(), req, req.Mode)
  418. entry, err := dir.maybeLoadEntry()
  419. if err != nil {
  420. return err
  421. }
  422. if req.Valid.Mode() {
  423. entry.Attributes.FileMode = uint32(req.Mode)
  424. }
  425. if req.Valid.Uid() {
  426. entry.Attributes.Uid = req.Uid
  427. }
  428. if req.Valid.Gid() {
  429. entry.Attributes.Gid = req.Gid
  430. }
  431. if req.Valid.Mtime() {
  432. entry.Attributes.Mtime = req.Mtime.Unix()
  433. }
  434. entry.Attributes.Mtime = time.Now().Unix()
  435. return dir.saveEntry(entry)
  436. }
  437. func (dir *Dir) Setxattr(ctx context.Context, req *fuse.SetxattrRequest) error {
  438. glog.V(4).Infof("dir Setxattr %s: %s", dir.FullPath(), req.Name)
  439. entry, err := dir.maybeLoadEntry()
  440. if err != nil {
  441. return err
  442. }
  443. if err := setxattr(entry, req); err != nil {
  444. return err
  445. }
  446. return dir.saveEntry(entry)
  447. }
  448. func (dir *Dir) Removexattr(ctx context.Context, req *fuse.RemovexattrRequest) error {
  449. glog.V(4).Infof("dir Removexattr %s: %s", dir.FullPath(), req.Name)
  450. entry, err := dir.maybeLoadEntry()
  451. if err != nil {
  452. return err
  453. }
  454. if err := removexattr(entry, req); err != nil {
  455. return err
  456. }
  457. return dir.saveEntry(entry)
  458. }
  459. func (dir *Dir) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
  460. glog.V(4).Infof("dir Listxattr %s", dir.FullPath())
  461. entry, err := dir.maybeLoadEntry()
  462. if err != nil {
  463. return err
  464. }
  465. if err := listxattr(entry, req, resp); err != nil {
  466. return err
  467. }
  468. return nil
  469. }
  470. func (dir *Dir) Forget() {
  471. glog.V(4).Infof("Forget dir %s", dir.FullPath())
  472. }
  473. func (dir *Dir) maybeLoadEntry() (*filer_pb.Entry, error) {
  474. parentDirPath, name := util.FullPath(dir.FullPath()).DirAndName()
  475. return dir.wfs.maybeLoadEntry(parentDirPath, name)
  476. }
  477. func (dir *Dir) saveEntry(entry *filer_pb.Entry) error {
  478. parentDir, name := util.FullPath(dir.FullPath()).DirAndName()
  479. return dir.wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  480. dir.wfs.mapPbIdFromLocalToFiler(entry)
  481. defer dir.wfs.mapPbIdFromFilerToLocal(entry)
  482. request := &filer_pb.UpdateEntryRequest{
  483. Directory: parentDir,
  484. Entry: entry,
  485. Signatures: []int32{dir.wfs.signature},
  486. }
  487. glog.V(1).Infof("save dir entry: %v", request)
  488. _, err := client.UpdateEntry(context.Background(), request)
  489. if err != nil {
  490. glog.Errorf("UpdateEntry dir %s/%s: %v", parentDir, name, err)
  491. return fuse.EIO
  492. }
  493. if err := dir.wfs.metaCache.UpdateEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  494. glog.Errorf("UpdateEntry dir %s/%s: %v", parentDir, name, err)
  495. return fuse.ESTALE
  496. }
  497. return nil
  498. })
  499. }
  500. func (dir *Dir) FullPath() string {
  501. var parts []string
  502. for p := dir; p != nil; p = p.parent {
  503. if strings.HasPrefix(p.name, "/") {
  504. if len(p.name) > 1 {
  505. parts = append(parts, p.name[1:])
  506. }
  507. } else {
  508. parts = append(parts, p.name)
  509. }
  510. }
  511. if len(parts) == 0 {
  512. return "/"
  513. }
  514. var buf bytes.Buffer
  515. for i := len(parts) - 1; i >= 0; i-- {
  516. buf.WriteString("/")
  517. buf.WriteString(parts[i])
  518. }
  519. return buf.String()
  520. }