fix(qsl): copy a design's pictures, not just its row

copyDirContents wrote into a destination it never created, so the first
os.Create returned ENOENT. The caller was written as "ignore os.IsNotExist"
— meant for a design with no pictures at all — and that guard matched the
failed write exactly: nothing was copied, no error surfaced, and validation
two lines later reported "copied design is incomplete: hero photo file
img_… not found" with no way to tell why.

Three fixes, one cause:

  - copyDirContents creates its destination;
  - the caller stats the source folder instead of pattern-matching an error,
    so a genuine copy failure is reported and rolls back both the row and
    the folder;
  - DuplicateProfile had the same defect in its own form — an INSERT … SELECT
    that cloned the template rows and left their photos behind, giving the
    new profile designs with no thumbnail and nothing to print. It now copies
    row and folder together, per template, since each needs its id first.

A test reproduces the original failure: it fails with the exact ENOENT that
was being swallowed.
This commit is contained in:
2026-08-14 11:57:35 +02:00
parent 4e88bdfaa7
commit 05fc8ad80c
4 changed files with 138 additions and 11 deletions
+8 -4
View File
@@ -1704,6 +1704,13 @@ func copyDirContents(src, dst string) error {
if err != nil {
return err
}
// Create the destination BEFORE writing into it. Without this the first
// os.Create failed with ENOENT, which reads as "not exist" — indistinguishable
// from a source folder that simply has nothing to copy, and callers testing
// for that swallowed it.
if err := os.MkdirAll(dst, 0o755); err != nil {
return err
}
for _, e := range entries {
srcPath := filepath.Join(src, e.Name())
dstPath := filepath.Join(dst, e.Name())
@@ -14099,10 +14106,7 @@ func (a *App) DuplicateProfile(id int64, newName string) (profile.Profile, error
applog.Printf("duplicate profile: copy operating: %v", err)
}
}
if _, err := a.db.ExecContext(a.ctx,
`INSERT INTO qsl_templates (name, profile_id, json, is_default, created_at, updated_at)
SELECT name, ?, json, is_default, created_at, updated_at
FROM qsl_templates WHERE profile_id = ?`, p.ID, id); err != nil {
if err := a.copyQSLTemplatesToProfile(id, p.ID); err != nil {
applog.Printf("duplicate profile: copy qsl templates: %v", err)
}
return p, nil