mirror of
https://github.com/gen2brain/cbconvert
synced 2026-09-04 04:31:11 +02:00
Copy non-image files out of a directory too
This commit is contained in:
+14
-8
@@ -187,7 +187,7 @@ func (c *Converter) convertArchive(ctx context.Context, fileName string) error {
|
||||
|
||||
// convertDirectory converts directory to CBZ.
|
||||
func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error {
|
||||
contents, err := imagesFromPath(dirPath)
|
||||
contents, err := filesFromPath(dirPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("convertDirectory: %w", err)
|
||||
}
|
||||
@@ -215,13 +215,7 @@ func (c *Converter) convertDirectory(ctx context.Context, dirPath string) error
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if isNonImage(img) && c.prefix == "" && !c.Opts.NoNonImage {
|
||||
if err = copyFile(file, c.workPath(flatName(rel))); err != nil {
|
||||
return fmt.Errorf("convertDirectory: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
} else if isImage(img) {
|
||||
if isImage(img) {
|
||||
if c.Opts.NoConvert {
|
||||
if err = copyFile(file, c.workPath(flatName(rel))); err != nil {
|
||||
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 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
|
||||
|
||||
@@ -59,6 +59,37 @@ func imagesFromSlice(files []string) []string {
|
||||
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.
|
||||
func isArchive(f string) bool {
|
||||
var types = []string{".rar", ".zip", ".7z", ".tar", ".cbr", ".cbz", ".cb7", ".cbt"}
|
||||
|
||||
Reference in New Issue
Block a user