Refactoring

This commit is contained in:
2025-01-06 20:00:00 +03:00
parent bcaeba5ea6
commit df4f2ebd99
2 changed files with 7 additions and 5 deletions

View File

@@ -43,7 +43,7 @@ func (a *Application) Start(ctx context.Context, wg *sync.WaitGroup) error {
WithDirMode(os.FileMode(a.config.DirMode)).
WithFileMode(os.FileMode(a.config.FileMode)).
WithErrLogger(func(err error) {
log.Println(err)
log.Println("ERROR:", err.Error())
})
if a.config.Overwrite {

View File

@@ -149,7 +149,7 @@ func (o *Organizer) Watch(ctx context.Context, wg *sync.WaitGroup) error {
// Add new directories to the watcher.
if stat.IsDir() {
if err := watcher.Add(event.Name); err != nil {
o.logErr(fmt.Errorf("watch dir: %w", err))
o.logErr(fmt.Errorf("add the directory %s to watcher: %w", event.Name, err))
}
continue
@@ -248,7 +248,7 @@ func (o *Organizer) processFile(sourcePath string) error {
return fmt.Errorf("build target path: %w", err)
}
if pathExists(targetPath) && !o.overwrite {
if o.pathExists(targetPath) && !o.overwrite {
return nil
}
@@ -283,7 +283,7 @@ func (o *Organizer) BuildTargetPath(sourcePath string, meta metadata.Metadata) (
}
func (o *Organizer) ensureTargetPath(targetPath string) error {
if pathExists(targetPath) {
if o.pathExists(targetPath) {
return nil
}
@@ -305,13 +305,15 @@ func (o *Organizer) ensureTargetPath(targetPath string) error {
return nil
}
func pathExists(path string) bool {
func (o *Organizer) pathExists(path string) bool {
_, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false
}
o.logErr(fmt.Errorf("pathExists stat %s: %w", path, err))
return true
}