Copy non-image files out of a directory too

This commit is contained in:
Milan Nikolic
2026-08-25 12:05:24 +02:00
parent 365ee2cdf9
commit 5d87cd59b6
2 changed files with 45 additions and 8 deletions
+14 -8
View File
@@ -187,7 +187,7 @@ func (c *Converter) convertArchive(ctx context.Context, fileName string) error {
// convertDirectory converts directory to CBZ. // convertDirectory converts directory to CBZ.
func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error { func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error {
contents, err := imagesFromPath(dirPath) contents, err := filesFromPath(dirPath)
if err != nil { if err != nil {
return fmt.Errorf("convertDirectory: %w", err) return fmt.Errorf("convertDirectory: %w", err)
} }
@@ -215,13 +215,7 @@ func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error
} }
defer file.Close() defer file.Close()
if isNonImage(img) && c.prefix == "" && !c.Opts.NoNonImage { if isImage(img) {
if err = copyFile(file, c.workPath(flatName(rel))); err != nil {
return fmt.Errorf("convertDirectory: %w", err)
}
return nil
} else if isImage(img) {
if c.Opts.NoConvert { if c.Opts.NoConvert {
if err = copyFile(file, c.workPath(flatName(rel))); err != nil { if err = copyFile(file, c.workPath(flatName(rel))); err != nil {
return fmt.Errorf("convertDirectory: %w", err) return fmt.Errorf("convertDirectory: %w", err)
@@ -249,6 +243,18 @@ func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error
return c.imageConvert(ctx, i, index, rel) return c.imageConvert(ctx, i, index, rel)
}) })
} }
return nil
}
if filepath.Ext(img) == ".DS_Store" || strings.Contains(img, "__MACOSX") {
return nil
}
if c.prefix == "" && !c.Opts.NoNonImage {
if err = copyFile(file, c.workPath(flatName(rel))); err != nil {
return fmt.Errorf("convertDirectory: %w", err)
}
} }
return nil return nil
+31
View File
@@ -59,6 +59,37 @@ func imagesFromSlice(files []string) []string {
return images return images
} }
// filesFromPath returns list of all found files for given directory.
func filesFromPath(path string) ([]string, error) {
var files []string
walkFiles := func(fp string, f os.FileInfo, err error) error {
if !f.IsDir() && f.Mode()&os.ModeType == 0 && f.Size() > 0 {
files = append(files, fp)
}
return nil
}
f, err := filepath.Abs(path)
if err != nil {
return files, fmt.Errorf("filesFromPath: %w", err)
}
stat, err := os.Stat(f)
if err != nil {
return files, fmt.Errorf("filesFromPath: %w", err)
}
if !stat.IsDir() && stat.Mode()&os.ModeType == 0 {
files = append(files, f)
} else if err = filepath.Walk(f, walkFiles); err != nil {
return files, fmt.Errorf("filesFromPath: %w", err)
}
return files, nil
}
// isArchive checks if a file is archive. // isArchive checks if a file is archive.
func isArchive(f string) bool { func isArchive(f string) bool {
var types = []string{".rar", ".zip", ".7z", ".tar", ".cbr", ".cbz", ".cb7", ".cbt"} var types = []string{".rar", ".zip", ".7z", ".tar", ".cbr", ".cbz", ".cb7", ".cbt"}