debugging
This commit is contained in:
parent
507e114908
commit
fdf31e22e4
@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -16,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func HandleFile(path string) (b *strings.Builder) {
|
func HandleFile(path string) (b *strings.Builder) {
|
||||||
b = &strings.Builder{}
|
b = &strings.Builder{}
|
||||||
b.WriteString(color.MagentaString("\nfile found: %s\n", path))
|
b.WriteString(color.MagentaString("%s file found: %s\n", time.Now().Format("2006-01-02 15:04:05"), path))
|
||||||
|
|
||||||
for _, parser := range parsers.Parsers {
|
for _, parser := range parsers.Parsers {
|
||||||
parsedFile, ok := parser.FileParser(&parser, path)
|
parsedFile, ok := parser.FileParser(&parser, path)
|
||||||
@ -57,8 +55,9 @@ func HandleParsedFile(b *strings.Builder, parsedFile *model.ParsedFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority {
|
if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority {
|
||||||
|
// TODO remove old file when overwriting existing episode (might have other file extension)
|
||||||
if err := OrganizeAnimeEpisode(b, parsedFile); err != nil {
|
if err := OrganizeAnimeEpisode(b, parsedFile); err != nil {
|
||||||
b.WriteString(color.RedString("\terror: %s", err.Error()))
|
b.WriteString(color.RedString("\terror: %s\n", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,52 +67,56 @@ func OrganizeAnimeEpisode(b *strings.Builder, parsedFile *model.ParsedFile) erro
|
|||||||
|
|
||||||
oldFile := filepath.Join(DownloadPath, parsedFile.File)
|
oldFile := filepath.Join(DownloadPath, parsedFile.File)
|
||||||
newFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), filepath.Ext(parsedFile.File))
|
newFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), filepath.Ext(parsedFile.File))
|
||||||
lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock")
|
//lockFile := logic.GetAnimeEpFilepath(parsedFile.AnimeEpisode(), "lock")
|
||||||
|
|
||||||
b.WriteString(color.BlueString("\tmove file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile))
|
b.WriteString(color.BlueString("\tmove file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile))
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil {
|
// if err := os.MkdirAll(filepath.Dir(newFile), os.ModePerm); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil {
|
// if err := os.Chown(filepath.Dir(newFile), Uid, Gid); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) {
|
// if _, err := os.Stat(newFile); !errors.Is(err, os.ErrNotExist) {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
inputFile, err := os.Open(oldFile)
|
// inputFile, err := os.Open(oldFile)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
defer inputFile.Close()
|
// defer inputFile.Close()
|
||||||
|
|
||||||
outputFile, err := os.Create(newFile)
|
// outputFile, err := os.Create(newFile)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
defer outputFile.Close()
|
// defer outputFile.Close()
|
||||||
|
|
||||||
if err := os.Chown(newFile, Uid, Gid); err != nil {
|
// if err := os.Chown(newFile, Uid, Gid); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
_, err = io.Copy(outputFile, inputFile)
|
// _, err = io.Copy(outputFile, inputFile)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if err = os.Remove(oldFile); err != nil {
|
// if err = os.Remove(oldFile); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
if err = os.Remove(lockFile); err != nil {
|
// if err = os.Remove(lockFile); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
b.WriteString(color.BlueString("\t done (took %s)\n", time.Since(start)))
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
n, err := b.WriteString(color.BlueString("\t done (took %s)\n", time.Since(start).Truncate(100*time.Millisecond)))
|
||||||
|
|
||||||
|
fmt.Println("ASD", n, err)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user