gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/renter/files.go (about) 1 package renter 2 3 import ( 4 "gitlab.com/SiaPrime/SiaPrime/modules" 5 "gitlab.com/SiaPrime/SiaPrime/modules/renter/siadir" 6 ) 7 8 // DeleteFile removes a file entry from the renter and deletes its data from 9 // the hosts it is stored on. 10 func (r *Renter) DeleteFile(siaPath modules.SiaPath) error { 11 if err := r.tg.Add(); err != nil { 12 return err 13 } 14 defer r.tg.Done() 15 16 // Call threadedBubbleMetadata on the old directory to make sure the system 17 // metadata is updated to reflect the move 18 defer func() error { 19 dirSiaPath, err := siaPath.Dir() 20 if err != nil { 21 return err 22 } 23 go r.threadedBubbleMetadata(dirSiaPath) 24 return nil 25 }() 26 27 return r.staticFileSet.Delete(siaPath) 28 } 29 30 // FileList returns all of the files that the renter has. 31 func (r *Renter) FileList(siaPath modules.SiaPath, recursive, cached bool) ([]modules.FileInfo, error) { 32 if err := r.tg.Add(); err != nil { 33 return []modules.FileInfo{}, err 34 } 35 defer r.tg.Done() 36 offlineMap, goodForRenewMap, contractsMap := r.managedContractUtilityMaps() 37 return r.staticFileSet.FileList(siaPath, recursive, cached, offlineMap, goodForRenewMap, contractsMap) 38 } 39 40 // File returns file from siaPath queried by user. 41 // Update based on FileList 42 func (r *Renter) File(siaPath modules.SiaPath) (modules.FileInfo, error) { 43 if err := r.tg.Add(); err != nil { 44 return modules.FileInfo{}, err 45 } 46 defer r.tg.Done() 47 offline, goodForRenew, contracts := r.managedContractUtilityMaps() 48 return r.staticFileSet.FileInfo(siaPath, offline, goodForRenew, contracts) 49 } 50 51 // RenameFile takes an existing file and changes the nickname. The original 52 // file must exist, and there must not be any file that already has the 53 // replacement nickname. 54 func (r *Renter) RenameFile(currentName, newName modules.SiaPath) error { 55 if err := r.tg.Add(); err != nil { 56 return err 57 } 58 defer r.tg.Done() 59 // Rename file 60 err := r.staticFileSet.Rename(currentName, newName) 61 if err != nil { 62 return err 63 } 64 // Call threadedBubbleMetadata on the old directory to make sure the system 65 // metadata is updated to reflect the move 66 dirSiaPath, err := currentName.Dir() 67 if err != nil { 68 return err 69 } 70 go r.threadedBubbleMetadata(dirSiaPath) 71 72 // Create directory metadata for new path, ignore errors if siadir already 73 // exists 74 dirSiaPath, err = newName.Dir() 75 if err != nil { 76 return err 77 } 78 err = r.CreateDir(dirSiaPath) 79 if err != siadir.ErrPathOverload && err != nil { 80 return err 81 } 82 // Call threadedBubbleMetadata on the new directory to make sure the system 83 // metadata is updated to reflect the move 84 go r.threadedBubbleMetadata(dirSiaPath) 85 return nil 86 } 87 88 // SetFileStuck sets the Stuck field of the whole siafile to stuck. 89 func (r *Renter) SetFileStuck(siaPath modules.SiaPath, stuck bool) error { 90 if err := r.tg.Add(); err != nil { 91 return err 92 } 93 defer r.tg.Done() 94 // Open the file. 95 entry, err := r.staticFileSet.Open(siaPath) 96 if err != nil { 97 return err 98 } 99 defer entry.Close() 100 // Update the file. 101 return entry.SetAllStuck(stuck) 102 }