| 1 | // Package tools contains other helper functions too small to justify their own package |
| 2 | // NOTE: Subject to change, do not rely on this package from outside git-lfs source |
| 3 | package toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ |
| 4 | |
| 5 | import ( |
| 6 | "encoding/hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 8 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 9 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 10 | "os/userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/" |
| 11 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 12 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 13 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 14 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 15 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 16 | "sync/atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/" |
| 17 | |
| 18 | "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/" |
| 19 | "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/" |
| 20 | ) |
| 21 | |
| 22 | // FileOrDirExists determines if a file/dir exists, returns IsDir() results too. |
| 23 | func FileOrDirExistsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FileOrDirExists().(path string) (exists bool, isDir bool) { |
| 24 | fi, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(path) |
| 25 | if err != nil { |
| 26 | return false, false |
| 27 | } else { |
| 28 | return true, fi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // FileExists determines if a file (NOT dir) exists. |
| 33 | func FileExistsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FileExists().(path string) bool { |
| 34 | ret, isDir := FileOrDirExistsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FileOrDirExists().(path) |
| 35 | return ret && !isDir |
| 36 | } |
| 37 | |
| 38 | // DirExists determines if a dir (NOT file) exists. |
| 39 | func DirExistsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirExists().(path string) bool { |
| 40 | ret, isDir := FileOrDirExistsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FileOrDirExists().(path) |
| 41 | return ret && isDir |
| 42 | } |
| 43 | |
| 44 | // FileExistsOfSize determines if a file exists and is of a specific size. |
| 45 | func FileExistsOfSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FileExistsOfSize().(path string, sz int64) bool { |
| 46 | fi, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(path) |
| 47 | |
| 48 | if err != nil { |
| 49 | return false |
| 50 | } |
| 51 | |
| 52 | return !fi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() && fi.Sizescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Size().() == sz |
| 53 | } |
| 54 | |
| 55 | // ResolveSymlinks ensures that if the path supplied is a symlink, it is |
| 56 | // resolved to the actual concrete path |
| 57 | func ResolveSymlinksscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ResolveSymlinks().(path string) string { |
| 58 | if len(path) == 0 { |
| 59 | return path |
| 60 | } |
| 61 | |
| 62 | if resolved, err := CanonicalizeSystemPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CanonicalizeSystemPath().(path); err == nil { |
| 63 | return resolved |
| 64 | } |
| 65 | return path |
| 66 | } |
| 67 | |
| 68 | // RenameFileCopyPermissions moves srcfile to destfile, replacing destfile if |
| 69 | // necessary and also copying the permissions of destfile if it already exists |
| 70 | func RenameFileCopyPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/RenameFileCopyPermissions().(srcfile, destfile string) error { |
| 71 | info, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(destfile) |
| 72 | if osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) { |
| 73 | // no original file |
| 74 | } else if err != nil { |
| 75 | return err |
| 76 | } else { |
| 77 | if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chmodscip-go gomod github.com/golang/go/src go1.25.0 os/Chmod().(srcfile, info.Modescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Mode().()); err != nil { |
| 78 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("can't set filemode on file %q: %v", srcfile, err)) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if err := RobustRenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/RobustRename().(srcfile, destfile); err != nil { |
| 83 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("cannot replace %q with %q: %v", destfile, srcfile, err)) |
| 84 | } |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | // CleanPaths splits the given `paths` argument by the delimiter argument, and |
| 89 | // then "cleans" that path according to the path.Clean function (see |
| 90 | // https://golang.org/pkg/path#Clean). |
| 91 | // Note always cleans to '/' path separators regardless of platform (git friendly) |
| 92 | func CleanPathsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CleanPaths().(paths, delim string) (cleaned []string) { |
| 93 | // If paths is an empty string, splitting it will yield [""], which will |
| 94 | // become the path ".". To avoid this, bail out if trimmed paths |
| 95 | // argument is empty. |
| 96 | if paths = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(paths); len(paths) == 0 { |
| 97 | return |
| 98 | } |
| 99 | |
| 100 | for _, part := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(paths, delim) { |
| 101 | part = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(part) |
| 102 | |
| 103 | // Remove trailing `/` or `\`, but only the first one. |
| 104 | for _, sep := range []string{`/`, `\`} { |
| 105 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasSuffix().(part, sep) { |
| 106 | part = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSuffix().(part, sep) |
| 107 | break |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | cleaned = append(cleaned, part) |
| 112 | } |
| 113 | |
| 114 | return cleaned |
| 115 | } |
| 116 | |
| 117 | // repositoryPermissionFetcher is an interface that matches the configuration |
| 118 | // object and can be used to fetch repository permissions. |
| 119 | type repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher# interface { |
| 120 | RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(executable bool) osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileModescip-go gomod github.com/golang/go/src go1.25.0 os/FileMode# |
| 121 | } |
| 122 | |
| 123 | // Mkdir makes a directory with the |
| 124 | // permissions specified by the core.sharedRepository setting. |
| 125 | func Mkdirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/Mkdir().(path string, config repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#) error { |
| 126 | umask := 0777 & ^config.RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(true) |
| 127 | return doWithUmaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/doWithUmask().(int(umask), func() error { |
| 128 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.Mkdirscip-go gomod github.com/golang/go/src go1.25.0 os/Mkdir().(path, config.RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(true)) |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | // MkdirAll makes a directory and any intervening directories with the |
| 133 | // permissions specified by the core.sharedRepository setting. |
| 134 | func MkdirAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/MkdirAll().(path string, config repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#) error { |
| 135 | umask := 0777 & ^config.RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(true) |
| 136 | return doWithUmaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/doWithUmask().(int(umask), func() error { |
| 137 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/MkdirAll().(path, config.RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(true)) |
| 138 | }) |
| 139 | } |
| 140 | |
| 141 | var ( |
| 142 | // currentUser is a wrapper over user.Current(), but instead uses the |
| 143 | // value of os.Getenv("HOME") for the returned *user.User's "HomeDir" |
| 144 | // member. |
| 145 | currentUserscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/currentUser. func() (*userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#, error) = func() (*userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#, error) { |
| 146 | u := &userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#{} |
| 147 | u.HomeDirscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#HomeDir. = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("HOME") |
| 148 | return u, nil |
| 149 | } |
| 150 | lookupUserscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/lookupUser. func(who string) (*userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#, error) = userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Lookupscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/Lookup(). |
| 151 | lookupConfigHomescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/lookupConfigHome. func() string = func() string { |
| 152 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("XDG_CONFIG_HOME") |
| 153 | } |
| 154 | ) |
| 155 | |
| 156 | // ExpandPath returns a copy of path with any references to the current user's |
| 157 | // home directory (spelled "~"), or a named user's home directory (spelled |
| 158 | // "~user") in the path, sanitized to the calling filesystem's path separator |
| 159 | // preference. |
| 160 | // |
| 161 | // If the "expand" argument is given as true, the resolved path to the named |
| 162 | // user's home directory will expanded with filepath.EvalSymlinks. |
| 163 | // |
| 164 | // If either the current or named user does not have a home directory, an error |
| 165 | // will be returned. |
| 166 | // |
| 167 | // Otherwise, the error returned will be nil, and the string returned will be |
| 168 | // the expanded path. |
| 169 | func ExpandPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ExpandPath().(path string, expand bool) (string, error) { |
| 170 | if len(path) == 0 || path[0] != '~' { |
| 171 | return path, nil |
| 172 | } |
| 173 | |
| 174 | var username string |
| 175 | if slash := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Indexscip-go gomod github.com/golang/go/src go1.25.0 strings/Index().(path[1:], "/"); slash > -1 { |
| 176 | username = path[1 : slash+1] |
| 177 | } else { |
| 178 | username = path[1:] |
| 179 | } |
| 180 | |
| 181 | var ( |
| 182 | who *userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/.Userscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User# |
| 183 | err error |
| 184 | ) |
| 185 | if len(username) == 0 { |
| 186 | who, err = currentUserscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/currentUser.() |
| 187 | } else { |
| 188 | who, err = lookupUserscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/lookupUser.(username) |
| 189 | } |
| 190 | |
| 191 | if err != nil { |
| 192 | return "", errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("could not find user %s", username)) |
| 193 | } |
| 194 | |
| 195 | homedir := who.HomeDirscip-go gomod github.com/golang/go/src go1.25.0 `os/user`/User#HomeDir. |
| 196 | if expand { |
| 197 | homedir, err = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.EvalSymlinksscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/EvalSymlinks().(homedir) |
| 198 | if err != nil { |
| 199 | return "", errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("cannot eval symlinks for %s", homedir)) |
| 200 | } |
| 201 | } |
| 202 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(homedir, path[len(username)+1:]), nil |
| 203 | } |
| 204 | |
| 205 | // ExpandConfigPath returns a copy of path expanded as with ExpandPath. If the |
| 206 | // path is empty, the default path is looked up inside $XDG_CONFIG_HOME, or |
| 207 | // ~/.config if that is not set. |
| 208 | func ExpandConfigPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ExpandConfigPath().(path, defaultPath string) (string, error) { |
| 209 | if path != "" { |
| 210 | return ExpandPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ExpandPath().(path, false) |
| 211 | } |
| 212 | |
| 213 | configHome := lookupConfigHomescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/lookupConfigHome.() |
| 214 | if configHome != "" { |
| 215 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(configHome, defaultPath), nil |
| 216 | } |
| 217 | |
| 218 | return ExpandPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ExpandPath().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("~/.config/%s", defaultPath), false) |
| 219 | } |
| 220 | |
| 221 | // VerifyFileHash reads a file and verifies whether the SHA is correct |
| 222 | // Returns an error if there is a problem |
| 223 | func VerifyFileHashscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/VerifyFileHash().(oid, path string) error { |
| 224 | f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Openscip-go gomod github.com/golang/go/src go1.25.0 os/Open().(path) |
| 225 | if err != nil { |
| 226 | return err |
| 227 | } |
| 228 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 229 | |
| 230 | h := NewLfsContentHashscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewLfsContentHash().() |
| 231 | _, err = ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Copyscip-go gomod github.com/golang/go/src go1.25.0 io/Copy().(h, f) |
| 232 | if err != nil { |
| 233 | return err |
| 234 | } |
| 235 | |
| 236 | calcOid := hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.EncodeToStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/EncodeToString().(h.Sumscip-go gomod github.com/golang/go/src go1.25.0 hash/Hash#Sum().(nil)) |
| 237 | if calcOid != oid { |
| 238 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("file %q has an invalid hash %s, expected %s", path, calcOid, oid)) |
| 239 | } |
| 240 | |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | // FastWalkCallback is the signature for the callback given to FastWalkGitRepo() |
| 245 | type FastWalkCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FastWalkCallback# func(parentDir string, info osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#, err error) |
| 246 | |
| 247 | // FastWalkDir is a more optimal implementation of filepath.Walk. |
| 248 | // The callback guaranteed to be called sequentially. The function returns |
| 249 | // once all files and errors have triggered callbacks. |
| 250 | // It differs in the following ways: |
| 251 | // - Uses goroutines to parallelise large dirs and descent into subdirs |
| 252 | // - Does not provide sorted output; parents will always be before children but |
| 253 | // there are no other guarantees. Use parentDir argument in the callback to |
| 254 | // determine absolute path rather than tracking it yourself |
| 255 | // |
| 256 | // dir - Absolute path to the directory |
| 257 | func FastWalkDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FastWalkDir().(dir string, cb FastWalkCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FastWalkCallback#) { |
| 258 | fastWalkCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkCallback().(fastWalkDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkDir().(dir), cb) |
| 259 | } |
| 260 | |
| 261 | // fastWalkCallback calls the FastWalkCallback "cb" for all files found by the |
| 262 | // given *fastWalker, "walker". |
| 263 | func fastWalkCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkCallback().(walker *fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#, cb FastWalkCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/FastWalkCallback#) { |
| 264 | for file := range walker.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. { |
| 265 | cb(file.ParentDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#ParentDir., file.Infoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Info., file.Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Err.) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Returned from FastWalk with parent directory context |
| 270 | // This is needed because FastWalk can provide paths out of order so the |
| 271 | // parent dir cannot be implied |
| 272 | type fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo# struct { |
| 273 | ParentDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#ParentDir. string |
| 274 | Infoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Info. osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo# |
| 275 | Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Err. error |
| 276 | } |
| 277 | |
| 278 | type fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker# struct { |
| 279 | dirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#dir. string |
| 280 | chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. chan fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo# |
| 281 | limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#limit. int32 |
| 282 | curscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#cur. *int32 |
| 283 | wgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#wg. *syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup# |
| 284 | } |
| 285 | |
| 286 | // fastWalkDir walks the contents of a dir |
| 287 | // |
| 288 | // dir - Absolute path to the directory |
| 289 | func fastWalkDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkDir().(dir string) *fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker# { |
| 290 | limit, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("LFS_FASTWALK_LIMIT")) |
| 291 | if limit < 1 { |
| 292 | limit = runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOMAXPROCS().(-1) * 20 |
| 293 | } |
| 294 | |
| 295 | c := int32(0) |
| 296 | w := &fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#{ |
| 297 | dirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#dir.: dir, |
| 298 | limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#limit.: int32(limit), |
| 299 | curscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#cur.: &c, |
| 300 | chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch.: make(chan fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#, 256), |
| 301 | wgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#wg.: &syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#{}, |
| 302 | } |
| 303 | |
| 304 | go func() { |
| 305 | defer w.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#Wait().() |
| 306 | |
| 307 | dirFi, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(w.dirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#dir.) |
| 308 | if err != nil { |
| 309 | w.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. <- fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#{Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Err.: err} |
| 310 | return |
| 311 | } |
| 312 | |
| 313 | w.Walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#Walk().(true, "", dirFi) |
| 314 | }() |
| 315 | return w |
| 316 | } |
| 317 | |
| 318 | // Walk is the main recursive implementation of fast walk. Sends the file/dir |
| 319 | // and any contents to the channel. Increments waitg.Add(1) for each new |
| 320 | // goroutine launched internally |
| 321 | // |
| 322 | // dir - Relative path inside the directory being walked |
| 323 | func (w *fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#) Walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#Walk().(isInitialDir bool, dir string, itemFi osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#) { |
| 324 | |
| 325 | var fullPath string // Absolute path to the current file or dir |
| 326 | var parentDir string // Absolute path to the parent of the current item |
| 327 | if isInitialDir { |
| 328 | fullPath = w.dirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#dir. |
| 329 | } else { |
| 330 | parentDir = joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/join().(w.dirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#dir., dir) |
| 331 | fullPath = joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/join().(parentDir, itemFi.Namescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Name().()) |
| 332 | } |
| 333 | |
| 334 | w.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. <- fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#{ParentDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#ParentDir.: parentDir, Infoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Info.: itemFi} |
| 335 | |
| 336 | if !itemFi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() { |
| 337 | // Nothing more to do if this is not a dir |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | var childDir string |
| 342 | if !isInitialDir { |
| 343 | childDir = joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/join().(dir, itemFi.Namescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Name().()) |
| 344 | } |
| 345 | |
| 346 | // The absolute optimal way to scan would be File.Readdirnames but we |
| 347 | // still need the Stat() to know whether something is a dir, so use |
| 348 | // File.Readdir instead. Means we can provide os.FileInfo to callers like |
| 349 | // filepath.Walk as a bonus. |
| 350 | df, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Openscip-go gomod github.com/golang/go/src go1.25.0 os/Open().(fullPath) |
| 351 | if err != nil { |
| 352 | w.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. <- fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#{Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Err.: err} |
| 353 | return |
| 354 | } |
| 355 | |
| 356 | // The number of items in a dir we process in each goroutine |
| 357 | jobSize := 100 |
| 358 | for children, err := df.Readdirscip-go gomod github.com/golang/go/src go1.25.0 os/File#Readdir().(jobSize); err == nil; children, err = df.Readdirscip-go gomod github.com/golang/go/src go1.25.0 os/File#Readdir().(jobSize) { |
| 359 | // Parallelise all dirs, and chop large dirs into batches |
| 360 | w.walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#walk().(children, func(subitems []osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#) { |
| 361 | for _, childFi := range subitems { |
| 362 | w.Walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#Walk().(false, childDir, childFi) |
| 363 | } |
| 364 | }) |
| 365 | } |
| 366 | |
| 367 | df.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 368 | if err != nil && err != ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF. { |
| 369 | w.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch. <- fastWalkInfoscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#{Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalkInfo#Err.: err} |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | func (w *fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#) walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#walk().(children []osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#, fn func([]osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#)) { |
| 374 | cur := atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/AddInt32().(w.curscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#cur., 1) |
| 375 | if cur > w.limitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#limit. { |
| 376 | fn(children) |
| 377 | atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/AddInt32().(w.curscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#cur., -1) |
| 378 | return |
| 379 | } |
| 380 | |
| 381 | w.wgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#wg..Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(1) |
| 382 | go func() { |
| 383 | fn(children) |
| 384 | w.wgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#wg..Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().() |
| 385 | atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/AddInt32().(w.curscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#cur., -1) |
| 386 | }() |
| 387 | } |
| 388 | |
| 389 | func (w *fastWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#) Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#Wait().() { |
| 390 | w.wgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#wg..Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().() |
| 391 | close(w.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/fastWalker#ch.) |
| 392 | } |
| 393 | |
| 394 | func joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/join().(paths ...string) string { |
| 395 | ne := make([]string, 0, len(paths)) |
| 396 | |
| 397 | for _, p := range paths { |
| 398 | if len(p) > 0 { |
| 399 | ne = append(ne, p) |
| 400 | } |
| 401 | } |
| 402 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(ne, "/") |
| 403 | } |
| 404 | |
| 405 | // SetFileWriteFlag changes write permissions on a file |
| 406 | // Used to make a file read-only or not. When writeEnabled = false, the write |
| 407 | // bit is removed for all roles. When writeEnabled = true, the behaviour is |
| 408 | // different per platform: |
| 409 | // On Mac & Linux, the write bit is set only on the owner as per default umask. |
| 410 | // All other bits are unaffected. |
| 411 | // On Windows, all the write bits are set since Windows doesn't support Unix permissions. |
| 412 | func SetFileWriteFlagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/SetFileWriteFlag().(path string, writeEnabled bool) error { |
| 413 | stat, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(path) |
| 414 | if err != nil { |
| 415 | return err |
| 416 | } |
| 417 | mode := uint32(stat.Modescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Mode().()) |
| 418 | |
| 419 | if (writeEnabled && (mode&0200) > 0) || |
| 420 | (!writeEnabled && (mode&0222) == 0) { |
| 421 | // no change needed |
| 422 | return nil |
| 423 | } |
| 424 | |
| 425 | if writeEnabled { |
| 426 | mode = mode | 0200 // set owner write only |
| 427 | // Go's own Chmod makes Windows set all though |
| 428 | } else { |
| 429 | mode = mode &^ 0222 // disable all write |
| 430 | } |
| 431 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chmodscip-go gomod github.com/golang/go/src go1.25.0 os/Chmod().(path, osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileModescip-go gomod github.com/golang/go/src go1.25.0 os/FileMode#(mode)) |
| 432 | } |
| 433 | |
| 434 | // TempFile creates a temporary file in specified directory with proper permissions for the repository. |
| 435 | // On success, it returns an open, non-nil *os.File, and the caller is responsible |
| 436 | // for closing and/or removing it. On failure, the temporary file is |
| 437 | // automatically cleaned up and an error returned. |
| 438 | // |
| 439 | // This function is designed to handle only temporary files that will be renamed |
| 440 | // into place later somewhere within the Git repository. |
| 441 | func TempFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TempFile().(dir, pattern string, cfg repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#) (*osscip-go gomod github.com/golang/go/src go1.25.0 os/.Filescip-go gomod github.com/golang/go/src go1.25.0 os/File#, error) { |
| 442 | tmp, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.CreateTempscip-go gomod github.com/golang/go/src go1.25.0 os/CreateTemp().(dir, pattern) |
| 443 | if err != nil { |
| 444 | return nil, err |
| 445 | } |
| 446 | |
| 447 | perms := cfg.RepositoryPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#RepositoryPermissions.(false) |
| 448 | err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Chmodscip-go gomod github.com/golang/go/src go1.25.0 os/Chmod().(tmp.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), perms) |
| 449 | if err != nil { |
| 450 | tmp.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 451 | osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(tmp.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().()) |
| 452 | return nil, err |
| 453 | } |
| 454 | return tmp, nil |
| 455 | } |
| 456 | |
| 457 | // ExecutablePermissions takes a set of Unix permissions (which may or may not |
| 458 | // have the executable bits set) and maps them into a set of permissions in |
| 459 | // which the executable bits are set, using the same technique as Git does. |
| 460 | func ExecutablePermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ExecutablePermissions().(perms osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileModescip-go gomod github.com/golang/go/src go1.25.0 os/FileMode#) osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileModescip-go gomod github.com/golang/go/src go1.25.0 os/FileMode# { |
| 461 | // Copy read bits to executable bits. |
| 462 | return perms | ((perms & 0444) >> 2) |
| 463 | } |
| 464 | |
| 465 | // CanonicalizePath takes a path and produces a canonical absolute path, |
| 466 | // performing any OS- or environment-specific path transformations (within the |
| 467 | // limitations of the Go standard library). If the path is empty, it returns |
| 468 | // the empty path with no error. If missingOk is true, then if the |
| 469 | // canonicalized path does not exist, an absolute path is given instead. |
| 470 | func CanonicalizePathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CanonicalizePath().(path string, missingOk bool) (string, error) { |
| 471 | path, err := TranslateCygwinPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TranslateCygwinPath().(path) |
| 472 | if err != nil { |
| 473 | return "", err |
| 474 | } |
| 475 | if len(path) > 0 { |
| 476 | path, err := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Absscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Abs().(path) |
| 477 | if err != nil { |
| 478 | return "", err |
| 479 | } |
| 480 | result, err := CanonicalizeSystemPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CanonicalizeSystemPath().(path) |
| 481 | if err != nil && osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) && missingOk { |
| 482 | return path, nil |
| 483 | } |
| 484 | return result, err |
| 485 | } |
| 486 | return "", nil |
| 487 | } |
| 488 | |
| 489 | const ( |
| 490 | windowsPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/windowsPrefix. = `.\` |
| 491 | nixPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/nixPrefix. = `./` |
| 492 | ) |
| 493 | |
| 494 | // TrimCurrentPrefix removes a leading prefix of "./" or ".\" (referring to the |
| 495 | // current directory in a platform independent manner). |
| 496 | // |
| 497 | // It is useful for callers such as "git lfs track" and "git lfs untrack", that |
| 498 | // wish to compare filepaths and/or attributes patterns without cleaning across |
| 499 | // multiple platforms. |
| 500 | func TrimCurrentPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TrimCurrentPrefix().(p string) string { |
| 501 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(p, windowsPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/windowsPrefix.) { |
| 502 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimPrefix().(p, windowsPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/windowsPrefix.) |
| 503 | } |
| 504 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimPrefix().(p, nixPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/nixPrefix.) |
| 505 | } |