| 1 | package tqscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 5 | "hashscip-go gomod github.com/golang/go/src go1.25.0 hash/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 7 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 9 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 10 | "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/" |
| 11 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 13 | |
| 14 | "github.com/git-lfs/git-lfs/v3/configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/" |
| 15 | "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`/" |
| 16 | "github.com/git-lfs/git-lfs/v3/toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/" |
| 17 | "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`/" |
| 18 | "github.com/klauspost/compress/zstdscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/" |
| 19 | "github.com/rubyist/tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/" |
| 20 | ) |
| 21 | |
| 22 | // Adapter for basic HTTP downloads, includes resuming via HTTP Range |
| 23 | type basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter# struct { |
| 24 | *adapterBasescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#adapterBase. |
| 25 | } |
| 26 | |
| 27 | type basicDownloadAdapterWorkerContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext# struct { |
| 28 | zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder. *zstdscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/.Decoderscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/Decoder# |
| 29 | } |
| 30 | |
| 31 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) tempDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#tempDir().() string { |
| 32 | // Shared with the SSH adapter. |
| 33 | d := 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().(a.fsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#fs..LFSStorageDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/fs`/Filesystem#LFSStorageDir., "incomplete") |
| 34 | if err := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.MkdirAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/MkdirAll().(d, a.fsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#fs.); err != nil { |
| 35 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.TempDirscip-go gomod github.com/golang/go/src go1.25.0 os/TempDir().() |
| 36 | } |
| 37 | return d |
| 38 | } |
| 39 | |
| 40 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) WorkerStartingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#WorkerStarting().(workerNum int) (interface{}, error) { |
| 41 | return &basicDownloadAdapterWorkerContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#{}, nil |
| 42 | } |
| 43 | |
| 44 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) WorkerEndingscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#WorkerEnding().(workerNum int, ctx interface{}) { |
| 45 | context, ok := ctx.(*basicDownloadAdapterWorkerContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#) |
| 46 | if !ok { |
| 47 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("context object for basic download transfer adapter was of the wrong type") |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | if context.zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder. != nil { |
| 52 | context.zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder..Closescip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/Decoder#Close().() |
| 53 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("http: closed zstd decoder") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) DoTransferscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#DoTransfer().(ctx interface{}, t *Transferscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#, cb ProgressCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/ProgressCallback#, authOkFunc func()) error { |
| 58 | context, ok := ctx.(*basicDownloadAdapterWorkerContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#) |
| 59 | if !ok { |
| 60 | 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().("context object for basic download transfer adapter was of the wrong type")) |
| 61 | } |
| 62 | |
| 63 | // Reserve a temporary filename. We need to make sure nobody operates on the file simultaneously with us. |
| 64 | f, err := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.TempFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TempFile().(a.tempDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#tempDir().(), t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., a.fsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#fs.) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | tmpName := f.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().() |
| 69 | defer func() { |
| 70 | // Fail-safe: Most implementation of os.File.Close() does nil check |
| 71 | if f != nil { |
| 72 | f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 73 | } |
| 74 | // This will delete temp file if: |
| 75 | // - we failed to fully download file and move it to final location including the case when final location already |
| 76 | // exists because other parallel git-lfs processes downloaded file |
| 77 | // - we also failed to move it to a partially-downloaded location |
| 78 | 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().(tmpName) |
| 79 | }() |
| 80 | |
| 81 | // Close file because we will attempt to move partially-downloaded one on top of it |
| 82 | if err := f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().(); err != nil { |
| 83 | return err |
| 84 | } |
| 85 | |
| 86 | // Attempt to resume download. No error checking here. If we fail, we'll simply download from the start |
| 87 | toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.RobustRenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/RobustRename().(a.downloadFilenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#downloadFilename().(t), f.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().()) |
| 88 | |
| 89 | // Open temp file. It is either empty or partially downloaded |
| 90 | f, err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenFilescip-go gomod github.com/golang/go/src go1.25.0 os/OpenFile().(f.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_RDWRscip-go gomod github.com/golang/go/src go1.25.0 os/O_RDWR., 0644) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | // Read any existing data into hash |
| 96 | hash := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.NewLfsContentHashscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewLfsContentHash().() |
| 97 | fromByte, 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().(hash, f) |
| 98 | if err != nil { |
| 99 | return err |
| 100 | } |
| 101 | |
| 102 | // Ensure that partial file seems valid |
| 103 | if fromByte > 0 { |
| 104 | if fromByte < t.Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Size.-1 { |
| 105 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("xfer: Attempting to resume download of %q from byte %d", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., fromByte) |
| 106 | } else { |
| 107 | // Somehow we have more data than expected. Let's retry from the beginning. |
| 108 | if _, err := f.Seekscip-go gomod github.com/golang/go/src go1.25.0 os/File#Seek().(0, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekStartscip-go gomod github.com/golang/go/src go1.25.0 io/SeekStart.); err != nil { |
| 109 | return err |
| 110 | } |
| 111 | if err := f.Truncatescip-go gomod github.com/golang/go/src go1.25.0 os/File#Truncate().(0); err != nil { |
| 112 | return err |
| 113 | } |
| 114 | fromByte = 0 |
| 115 | hash = nil |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | err = a.downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#download().(context, t, cb, authOkFunc, f, fromByte, hash) |
| 120 | |
| 121 | if err != nil { |
| 122 | f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 123 | // Rename file so next download can resume from where we stopped. |
| 124 | // No error checking here, if rename fails then file will be deleted and there just will be no download resuming |
| 125 | toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.RobustRenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/RobustRename().(f.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().(), a.downloadFilenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#downloadFilename().(t)) |
| 126 | } |
| 127 | |
| 128 | return err |
| 129 | } |
| 130 | |
| 131 | // Returns path where partially downloaded file should be stored for download resuming |
| 132 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) downloadFilenamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#downloadFilename().(t *Transferscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#) string { |
| 133 | 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().(a.tempDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#tempDir().(), t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid.+".part") |
| 134 | } |
| 135 | |
| 136 | // download starts or resumes and download. dlFile is expected to be an existing file open in RW mode |
| 137 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#download().(context *basicDownloadAdapterWorkerContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#, t *Transferscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#, cb ProgressCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/ProgressCallback#, authOkFunc func(), dlFile *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#, fromByte int64, hash hashscip-go gomod github.com/golang/go/src go1.25.0 hash/.Hashscip-go gomod github.com/golang/go/src go1.25.0 hash/Hash#) error { |
| 138 | rel, err := t.Relscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Rel().("download") |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | if rel == nil { |
| 143 | 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().("Object %s not found on the server.", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid.)) |
| 144 | } |
| 145 | |
| 146 | req, err := a.newHTTPRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#newHTTPRequest().("GET", rel) |
| 147 | if err != nil { |
| 148 | return err |
| 149 | } |
| 150 | |
| 151 | if fromByte > 0 { |
| 152 | // We could just use a start byte, but since we know the length be specific |
| 153 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Range", 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().("bytes=%d-%d", fromByte, t.Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Size.-1)) |
| 154 | } else { |
| 155 | // Set Accept-Encoding header if configured to zstd |
| 156 | // (Go's http client handles gzip automatically when no Accept-Encoding is set) |
| 157 | uc := configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/.NewURLConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/NewURLConfig().(a.apiClientscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#apiClient..GitEnvscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfsapi`/Client#GitEnv().()) |
| 158 | httpDownloadEncoding, _ := uc.Getscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/URLConfig#Get().("lfs.transfer", rel.Hrefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Action#Href., "httpdownloadencoding") |
| 159 | if httpDownloadEncoding != "" { |
| 160 | switch httpDownloadEncoding { |
| 161 | case "gzip": |
| 162 | // Don't set header, let Go's http client handle gzip automatically |
| 163 | case "zstd": |
| 164 | req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Set().("Accept-Encoding", "zstd") |
| 165 | default: |
| 166 | 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().("unsupported lfs.transfer.httpDownloadEncoding value %q: must be \"gzip\" or \"zstd\"", httpDownloadEncoding)) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | req = a.apiClientscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#apiClient..LogRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfsapi`/Client#LogRequest().(req, "lfs.data.download") |
| 172 | res, err := a.makeRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#makeRequest().(t, req) |
| 173 | if err != nil { |
| 174 | if res == nil { |
| 175 | // We encountered a network or similar error which caused us |
| 176 | // to not receive a response at all. |
| 177 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.NewRetriableErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/NewRetriableError().(err) |
| 178 | } |
| 179 | |
| 180 | // Special-case status code 416 () - fall back |
| 181 | if fromByte > 0 && dlFile != nil && res.StatusCodescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#StatusCode. == 416 { |
| 182 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("xfer: server rejected resume download request for %q from byte %d; re-downloading from start", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., fromByte) |
| 183 | if _, err := dlFile.Seekscip-go gomod github.com/golang/go/src go1.25.0 os/File#Seek().(0, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekStartscip-go gomod github.com/golang/go/src go1.25.0 io/SeekStart.); err != nil { |
| 184 | return err |
| 185 | } |
| 186 | if err := dlFile.Truncatescip-go gomod github.com/golang/go/src go1.25.0 os/File#Truncate().(0); err != nil { |
| 187 | return err |
| 188 | } |
| 189 | return a.downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#download().(context, t, cb, authOkFunc, dlFile, 0, nil) |
| 190 | } |
| 191 | |
| 192 | // Special-cae status code 429 - retry after certain time |
| 193 | if res.StatusCodescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#StatusCode. == 429 { |
| 194 | retLaterErr := errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.NewRetriableLaterErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/NewRetriableLaterError().(err, res.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Retry-After")) |
| 195 | if retLaterErr != nil { |
| 196 | return retLaterErr |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.NewRetriableErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/NewRetriableError().(err) |
| 201 | } |
| 202 | |
| 203 | defer res.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.25.0 io/Closer#Close().() |
| 204 | |
| 205 | // Range request must return 206 & content range to confirm |
| 206 | if fromByte > 0 { |
| 207 | rangeRequestOk := false |
| 208 | var failReason string |
| 209 | // check 206 and Content-Range, fall back if either not as expected |
| 210 | if res.StatusCodescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#StatusCode. == 206 { |
| 211 | // Probably a successful range request, check Content-Range |
| 212 | if rangeHdr := res.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Content-Range"); rangeHdr != "" { |
| 213 | regex := regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`bytes (\d+)\-.*`) |
| 214 | match := regex.FindStringSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindStringSubmatch().(rangeHdr) |
| 215 | if match != nil && len(match) > 1 { |
| 216 | contentStart, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseInt().(match[1], 10, 64) |
| 217 | if contentStart == fromByte { |
| 218 | rangeRequestOk = true |
| 219 | } else { |
| 220 | failReason = 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().("Content-Range start byte incorrect: %s expected %d", match[1], fromByte) |
| 221 | } |
| 222 | } else { |
| 223 | failReason = 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().("badly formatted Content-Range header: %q", rangeHdr) |
| 224 | } |
| 225 | } else { |
| 226 | failReason = "missing Content-Range header in response" |
| 227 | } |
| 228 | } else { |
| 229 | failReason = 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().("expected status code 206, received %d", res.StatusCodescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#StatusCode.) |
| 230 | } |
| 231 | if rangeRequestOk { |
| 232 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("xfer: server accepted resume download request: %q from byte %d", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., fromByte) |
| 233 | advanceCallbackProgressscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/advanceCallbackProgress().(cb, t, fromByte) |
| 234 | } else { |
| 235 | // Abort resume, perform regular download |
| 236 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("xfer: failed to resume download for %q from byte %d: %s. Re-downloading from start", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., fromByte, failReason) |
| 237 | |
| 238 | if _, err := dlFile.Seekscip-go gomod github.com/golang/go/src go1.25.0 os/File#Seek().(0, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekStartscip-go gomod github.com/golang/go/src go1.25.0 io/SeekStart.); err != nil { |
| 239 | return err |
| 240 | } |
| 241 | if err := dlFile.Truncatescip-go gomod github.com/golang/go/src go1.25.0 os/File#Truncate().(0); err != nil { |
| 242 | return err |
| 243 | } |
| 244 | fromByte = 0 |
| 245 | hash = nil |
| 246 | |
| 247 | if res.StatusCodescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#StatusCode. == 200 { |
| 248 | // If status code was 200 then server just ignored Range header and |
| 249 | // sent everything. Don't re-request, use this one from byte 0 |
| 250 | } else { |
| 251 | // re-request needed |
| 252 | return a.downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#download().(context, t, cb, authOkFunc, dlFile, fromByte, hash) |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // Signal auth OK on success response, before starting download to free up |
| 258 | // other workers immediately |
| 259 | if authOkFunc != nil { |
| 260 | authOkFunc() |
| 261 | } |
| 262 | |
| 263 | // Handle Content-Encoding decompression for zstd |
| 264 | // (gzip is handled automatically by Go's http client when we don't set Accept-Encoding) |
| 265 | var bodyReader ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader# = res.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Body. |
| 266 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(res.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Content-Encoding")) == "zstd" { |
| 267 | zstdDecoder := context.zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder. |
| 268 | if zstdDecoder == nil { |
| 269 | zstdDecoder, err := zstdscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/.NewReaderscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/NewReader().(res.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Body., zstdscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/.WithDecoderConcurrencyscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/WithDecoderConcurrency().(1)) |
| 270 | if err != nil { |
| 271 | 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().("failed to create zstd decompressor")) |
| 272 | } |
| 273 | context.zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder. = zstdDecoder |
| 274 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("http: initialized zstd decoder") |
| 275 | } else { |
| 276 | zstdDecoder.Resetscip-go gomod github.com/klauspost/compress v1.19.1 `github.com/klauspost/compress/zstd`/Decoder#Reset().(res.Bodyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#Body.) |
| 277 | } |
| 278 | bodyReader = context.zstdDecoderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapterWorkerContext#zstdDecoder. |
| 279 | |
| 280 | tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("http: decompressing zstd-encoded response") |
| 281 | |
| 282 | // Set ContentLength to -1 to match Go's default behaviour |
| 283 | // when decompressing gzipped responses; see: |
| 284 | // |
| 285 | // https://github.com/golang/go/blob/go1.25.7/src/net/http/response.go#L90-L92 |
| 286 | // https://github.com/golang/go/blob/go1.25.7/src/net/http/transport.go#L2385 |
| 287 | res.ContentLengthscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#ContentLength. = -1 |
| 288 | } |
| 289 | |
| 290 | var hasher *toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.HashingReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/HashingReader# |
| 291 | httpReader := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.NewRetriableReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewRetriableReader().(bodyReader) |
| 292 | |
| 293 | if fromByte > 0 && hash != nil { |
| 294 | // pre-load hashing reader with previous content |
| 295 | hasher = toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.NewHashingReaderPreloadHashscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewHashingReaderPreloadHash().(httpReader, hash) |
| 296 | } else { |
| 297 | hasher = toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.NewHashingReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewHashingReader().(httpReader) |
| 298 | } |
| 299 | |
| 300 | dlfilename := dlFile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().() |
| 301 | // Wrap callback to give name context |
| 302 | ccb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 303 | if cb != nil { |
| 304 | return cb(t.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Name., totalSize, readSoFar+fromByte, readSinceLast) |
| 305 | } |
| 306 | return nil |
| 307 | } |
| 308 | written, err := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.CopyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CopyWithCallback().(dlFile, hasher, res.ContentLengthscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#ContentLength., ccb) |
| 309 | if err != nil { |
| 310 | 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 write data to temporary file %q", dlfilename)) |
| 311 | } |
| 312 | |
| 313 | if actual := hasher.Hashscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/HashingReader#Hash().(); actual != t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid. { |
| 314 | 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().("expected OID %s, got %s after %d bytes written", t.Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Oid., actual, written)) |
| 315 | } |
| 316 | |
| 317 | if err := dlFile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().(); err != nil { |
| 318 | 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 close temporary file %q: %v", dlfilename, err)) |
| 319 | } |
| 320 | |
| 321 | err = toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.RenameFileCopyPermissionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/RenameFileCopyPermissions().(dlfilename, t.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Path.) |
| 322 | if _, err2 := 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().(t.Pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#Path.); err2 == nil { |
| 323 | // Target file already exists, possibly was downloaded by other git-lfs process |
| 324 | return nil |
| 325 | } |
| 326 | return err |
| 327 | } |
| 328 | |
| 329 | func configureBasicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/configureBasicDownloadAdapter().(m *concreteManifestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/concreteManifest#) { |
| 330 | m.RegisterNewAdapterFuncscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/concreteManifest#RegisterNewAdapterFunc().(BasicAdapterNamescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/BasicAdapterName., Downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Download., false, func(name string, dir Directionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Direction#) Adapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Adapter# { |
| 331 | switch dir { |
| 332 | case Downloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Download.: |
| 333 | bd := &basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#{newAdapterBasescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/newAdapterBase().(m.fsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/concreteManifest#fs., name, dir, nil)} |
| 334 | // self implements impl |
| 335 | bd.transferImplscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#transferImpl. = bd |
| 336 | return bd |
| 337 | case Uploadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Upload.: |
| 338 | panic(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().("Should never ask this function to upload")) |
| 339 | } |
| 340 | return nil |
| 341 | }) |
| 342 | } |
| 343 | |
| 344 | func (a *basicDownloadAdapterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#) makeRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#makeRequest().(t *Transferscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/Transfer#, req *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Response#, error) { |
| 345 | res, err := a.doHTTPscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/adapterBase#doHTTP().(t, req) |
| 346 | if errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.IsAuthErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/IsAuthError().(err) && len(req.Headerscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Header#Get().("Authorization")) == 0 { |
| 347 | return a.makeRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tq`/basicDownloadAdapter#makeRequest().(t, req) |
| 348 | } |
| 349 | |
| 350 | return res, err |
| 351 | } |