Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Simplify release file management

fdd0b3e8373da4c684c73d88f997c3917966ac50 · Keenan Nemetz · 17d ago · parent c5187449

Simplify release file management

Drop rename and move from the CLI and browser, outline the files table instead of wrapping it in a card, and label the release-page action Manage files.

metadata/releases.go +1−64

@@ -155,7 +155,7 @@ func validReleaseTag(tag string) error {
155 155 // pointerAt reads the artifact pointer at name out of a flat metadata tree. A
156 156 // missing path and a path holding something other than a pointer are both "not
157 157 // an artifact": a hand-written note in the release directory is not a file the
158 // release managers may move or delete.
158 // release managers may delete.
159 159 func pointerAt(files map[string][]byte, tag, name string) (lfs.Pointer, bool) {
160 160 body, ok := files[ReleasePath(tag, name)]
161 161 if !ok {
@@ -165,26 +165,6 @@ func pointerAt(files map[string][]byte, tag, name string) (lfs.Pointer, bool) {
165 165 return p, ok
166 166 }
167 167
168 // artifactPaths is the set of artifact names in one flat tree for tag. It is
169 // used to refuse a move that would turn a file into a directory or the reverse.
170 func artifactPaths(files map[string][]byte, tag string) map[string]bool {
171 prefix := ReleasesDir + "/" + tag + "/"
172 out := map[string]bool{}
173 for path, body := range files {
174 if !strings.HasPrefix(path, prefix) {
175 continue
176 }
177 name := strings.TrimPrefix(path, prefix)
178 if ValidArtifactPath(name) != nil {
179 continue
180 }
181 if _, ok := lfs.ParsePointer(body); ok {
182 out[name] = true
183 }
184 }
185 return out
186 }
187
188 168 // WritePointers records artifacts on the metadata branch, one literal LFS
189 169 // pointer per path. It starts from the branch's current tree, so applying it
190 170 // again after a lost push race is idempotent.
@@ -206,49 +186,6 @@ func WriteReleasePointers(g *git.Repo, ref, tag string, arts []Artifact, message
206 186 return err
207 187 }
208 188
209 // MoveReleasePointer renames or moves one attached file. The pointer bytes are
210 // unchanged: only the path under releases/<tag>/ moves, so the object store still
211 // holds one copy of the content. The destination must not already be an artifact
212 // and must not conflict with the file/directory shape of the remaining tree; a
213 // caller that wants to replace a file attaches over it instead.
214 func MoveReleasePointer(g *git.Repo, ref, tag, from, to, message, author string) error {
215 if err := validReleaseTag(tag); err != nil {
216 return err
217 }
218 for _, name := range []string{from, to} {
219 if err := ValidArtifactPath(name); err != nil {
220 return err
221 }
222 }
223 if from == to {
224 return fmt.Errorf("%s is already the path of that file", from)
225 }
226 _, err := git.CommitFiles(g, ref, func(files map[string][]byte) error {
227 pointer, ok := pointerAt(files, tag, from)
228 if !ok {
229 return fmt.Errorf("%s is not an attached file of %s", from, tag)
230 }
231 if _, exists := pointerAt(files, tag, to); exists {
232 return fmt.Errorf("%s is already attached to %s; remove it first or choose another path", to, tag)
233 }
234 for name := range artifactPaths(files, tag) {
235 if name == from {
236 continue
237 }
238 if strings.HasPrefix(to, name+"/") {
239 return fmt.Errorf("%s is a file on this release, so %s cannot move under it", name, to)
240 }
241 if strings.HasPrefix(name, to+"/") {
242 return fmt.Errorf("%s is a directory on this release, so %s cannot move to that path", name, to)
243 }
244 }
245 delete(files, ReleasePath(tag, from))
246 files[ReleasePath(tag, to)] = pointer.Encode()
247 return nil
248 }, message, author)
249 return err
250 }
251
252 189 // RemoveReleasePointers deletes attached files from one release. Each named path
253 190 // must still be an artifact: a removal that silently did nothing would leave the
254 191 // caller believing the file is gone. The bytes stay in the content-addressed