Add shared live run graphs, debugging, editor choice and draft cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Draft struct {
|
||||
@@ -114,3 +115,36 @@ func List() ([]Draft, error) {
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// Delete only a selected, managed cache draft and its sidecar. Never recurse,
|
||||
// follow a file symlink, or delete an arbitrary external submission source.
|
||||
func Delete(path string) error {
|
||||
dir, err := Directory()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absolute, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name := filepath.Base(absolute)
|
||||
if filepath.Dir(absolute) != filepath.Clean(dir) || !strings.HasPrefix(name, "pipeline-") || !strings.HasSuffix(name, ".md") {
|
||||
return fmt.Errorf("only managed drafts inside %s can be deleted", dir)
|
||||
}
|
||||
for _, file := range []string{absolute + ".json", absolute} {
|
||||
info, err := os.Lstat(file)
|
||||
if os.IsNotExist(err) && file == absolute {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
return fmt.Errorf("draft and metadata must be regular files, not symlinks or directories")
|
||||
}
|
||||
}
|
||||
if err := os.Remove(absolute); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return os.Remove(absolute + ".json")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user