# HG changeset patch # User Ted Unangst # Date 1712117736 14400 # Wed Apr 03 00:15:36 2024 -0400 # Node ID f381c9b1afd02965a2431b1c70168678abc32d2f # Parent 88385ed9abbb60c1d164552f12494c60f31dab3e confine the madness to backup code, and hardlink attachments diff --git a/backupdb.go b/backupdb.go --- a/backupdb.go +++ b/backupdb.go @@ -182,6 +182,7 @@ backup.Close() var blob *sql.DB + var filesavepath string if storeTheFilesInTheFileSystem { filesavepath = fmt.Sprintf("%s/attachments-%d", dirname, now) os.Mkdir(filesavepath, 0700) @@ -203,12 +204,27 @@ checkErr(err) } for xid := range filexids { + if storeTheFilesInTheFileSystem { + oldname := filepath(xid) + newname := filesavepath + oldname[14:] + os.Mkdir(newname[:strings.LastIndexByte(newname, '/')], 0700) + err = os.Link(oldname, newname) + if err == nil { + continue + } + } data, closer, err := loaddata(xid) if err != nil { elog.Printf("lost a file: %s", xid) continue } - err = savefiledata(xid, data) + if storeTheFilesInTheFileSystem { + oldname := filepath(xid) + newname := filesavepath + oldname[14:] + err = os.WriteFile(newname, data, 0700) + } else { + _, err = stmtSaveBlobData.Exec(xid, data) + } if err != nil { elog.Printf("failed to save file %s: %s", xid, err) } diff --git a/filestoragemanagerfactory.go b/filestoragemanagerfactory.go --- a/filestoragemanagerfactory.go +++ b/filestoragemanagerfactory.go @@ -50,14 +50,9 @@ return fileid, err } -var filesavepath = "" // used to redirect backups - func savefiledata(xid string, data []byte) error { if storeTheFilesInTheFileSystem { fname := filepath(xid) - if filesavepath != "" { - fname = filesavepath + fname[14:] - } os.Mkdir(fname[:strings.LastIndexByte(fname, '/')], 0700) err := os.WriteFile(fname, data, 0700) return err