feat: add --backup-converted flag to keep .orig backups
This commit is contained in:
@@ -44,6 +44,7 @@ type MirrorConfig struct {
|
||||
ConvertLinks bool // Convert links for local viewing
|
||||
DownloadAssets bool // Download CSS, JS, images
|
||||
PruneEmpty bool // Remove empty directories after download
|
||||
BackupConverted bool // Keep .orig backup before link conversion
|
||||
RestrictFiles bool // Only download files from original host
|
||||
Timeout time.Duration
|
||||
RateLimiter *transport.TokenBucket
|
||||
@@ -642,6 +643,16 @@ func (m *Mirror) convertLinksInFile(filePath string) {
|
||||
converted := m.rewriter.RewriteLinks(doc, filePath)
|
||||
|
||||
if converted > 0 {
|
||||
// Backup original file before link conversion.
|
||||
if m.config.BackupConverted {
|
||||
backupPath := filePath + ".orig"
|
||||
if err := os.WriteFile(backupPath, data, 0644); err != nil {
|
||||
if m.config.Verbose {
|
||||
fmt.Fprintf(os.Stderr, "[error] failed to backup %s: %v\n", filePath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write modified HTML
|
||||
var buf bytes.Buffer
|
||||
if err := html.Render(&buf, doc); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user