github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/repository/tracker/nibSearchResponse.go (about) 1 package tracker 2 3 import ( 4 "os" 5 "path/filepath" 6 ) 7 8 // NewNIBSearchResponse returns a initialized NIBSearchResponse struct with the 9 // given parameters. 10 func NewNIBSearchResponse(NIBID string, path string, repositoryPath string) *NIBSearchResponse { 11 return &NIBSearchResponse{ 12 NIBID: NIBID, 13 Path: path, 14 repositoryPath: repositoryPath, 15 } 16 } 17 18 // NIBSearchResponse is being returned by NIBTracker implementations 19 // to indicate that a NIB for the path exists. 20 type NIBSearchResponse struct { 21 NIBID string 22 Path string 23 repositoryPath string 24 } 25 26 // AbsPath returns the absolute path the stored NIBID is being 27 // associated to. 28 func (r *NIBSearchResponse) AbsPath() string { 29 path := filepath.Join(r.repositoryPath, r.Path) 30 absPath, err := filepath.Abs(path) 31 if err != nil { 32 return path 33 } 34 symlinkResolve, err := filepath.EvalSymlinks(absPath) 35 if err != nil { 36 return absPath 37 } 38 return symlinkResolve 39 } 40 41 // FileExists returns if the path still has a file stored. 42 func (r *NIBSearchResponse) FileExists() bool { 43 stat, err := os.Stat(r.AbsPath()) 44 if err != nil || stat.IsDir() { 45 return false 46 } 47 return true 48 }