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.

Manage release files from the CLI and browser

c51874492382d08085b6388cea898d0d60ab9375 · Keenan Nemetz · 17d ago · parent 214e7ea6

Manage release files from the CLI and browser

Move the attach form to its own page, add move/remove operations to the CLI and browser, and simplify the release detail page to notes, files, and source links.

metadata/releases.go +127−4

@@ -139,16 +139,59 @@ func ReleaseProblems(g *git.Repo, commit string) []string {
139 139 return problems
140 140 }
141 141
142 // WritePointers records artifacts on the metadata branch, one literal LFS
143 // pointer per path. It starts from the branch's current tree, so applying it
144 // again after a lost push race is idempotent.
145 func WriteReleasePointers(g *git.Repo, ref, tag string, arts []Artifact, message, author string) error {
142 // validReleaseTag checks the segment between releases/ and the artifact path.
143 // A tag containing '/' would make releases/<tag>/<path> ambiguous, and every
144 // writer and reader of the tree uses the same rule.
145 func validReleaseTag(tag string) error {
146 146 if strings.Contains(tag, "/") {
147 147 return fmt.Errorf("release tag %q must not contain '/'; an artifact path is ambiguous after it", tag)
148 148 }
149 149 if err := ValidArtifactPath(tag); err != nil {
150 150 return fmt.Errorf("release tag %q: %w", tag, err)
151 151 }
152 return nil
153 }
154
155 // pointerAt reads the artifact pointer at name out of a flat metadata tree. A
156 // missing path and a path holding something other than a pointer are both "not
157 // an artifact": a hand-written note in the release directory is not a file the
158 // release managers may move or delete.
159 func pointerAt(files map[string][]byte, tag, name string) (lfs.Pointer, bool) {
160 body, ok := files[ReleasePath(tag, name)]
161 if !ok {
162 return lfs.Pointer{}, false
163 }
164 p, ok := lfs.ParsePointer(body)
165 return p, ok
166 }
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 // WritePointers records artifacts on the metadata branch, one literal LFS
189 // pointer per path. It starts from the branch's current tree, so applying it
190 // again after a lost push race is idempotent.
191 func WriteReleasePointers(g *git.Repo, ref, tag string, arts []Artifact, message, author string) error {
192 if err := validReleaseTag(tag); err != nil {
193 return err
194 }
152 195 for _, a := range arts {
153 196 if err := ValidArtifactPath(a.Name); err != nil {
154 197 return err
@@ -163,6 +206,86 @@ func WriteReleasePointers(g *git.Repo, ref, tag string, arts []Artifact, message
163 206 return err
164 207 }
165 208
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 // RemoveReleasePointers deletes attached files from one release. Each named path
253 // must still be an artifact: a removal that silently did nothing would leave the
254 // caller believing the file is gone. The bytes stay in the content-addressed
255 // store until gc finds no pointer to them.
256 func RemoveReleasePointers(g *git.Repo, ref, tag string, names []string, message, author string) error {
257 if err := validReleaseTag(tag); err != nil {
258 return err
259 }
260 if len(names) == 0 {
261 return fmt.Errorf("no artifact path given")
262 }
263 seen := make(map[string]bool, len(names))
264 unique := make([]string, 0, len(names))
265 for _, name := range names {
266 if err := ValidArtifactPath(name); err != nil {
267 return err
268 }
269 if seen[name] {
270 continue
271 }
272 seen[name] = true
273 unique = append(unique, name)
274 }
275 _, err := git.CommitFiles(g, ref, func(files map[string][]byte) error {
276 for _, name := range unique {
277 if _, ok := pointerAt(files, tag, name); !ok {
278 return fmt.Errorf("%s is not an attached file of %s", name, tag)
279 }
280 }
281 for _, name := range unique {
282 delete(files, ReleasePath(tag, name))
283 }
284 return nil
285 }, message, author)
286 return err
287 }
288
166 289 // LoadArtifactsAt reads every release artifact on the metadata branch at commit,
167 290 // keyed by tag. It is one tree listing and one blob read for the whole set: a
168 291 // release with fifty files is not fifty processes, and the index reads the set to