From 91dadf67dbbf374bc21f46af721610ba0143dafb Mon Sep 17 00:00:00 2001 From: Madeline Hashcube Date: Mon, 25 May 2026 13:49:41 -0500 Subject: [PATCH] Syncing fully works --- cmd/ytpm/sync.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/cmd/ytpm/sync.go b/cmd/ytpm/sync.go index 23165b0..0b49141 100644 --- a/cmd/ytpm/sync.go +++ b/cmd/ytpm/sync.go @@ -25,7 +25,9 @@ func SyncSources() (int, error) { err = os.Mkdir(downloadsDir, cacheInfo.Mode()) if err != nil { - return 0, err + if err.Error() != "mkdir " + downloadsDir + ": file exists" { + return 0, err + } } cmd := ytdlp.New(). @@ -67,7 +69,24 @@ func SyncSources() (int, error) { srcCount := 0 - for _, sources := range manifestData.Sources { + sourcesPath := cwd + "/sources/" + + err = os.Mkdir(sourcesPath, cacheInfo.Mode()) + if err != nil { + if err.Error() != "mkdir " + sourcesPath + ": file exists" { + return 0, err + } + } + + for key, sources := range manifestData.Sources { + if key == "default" { key = "" } + keyPath := sourcesPath + key + "/" + err = os.Mkdir(keyPath, cacheInfo.Mode()) + if err != nil { + if err.Error() != "mkdir " + keyPath + ": file exists" { + return 0, err + } + } for _, source := range sources { res, err := cmd.Run(context.TODO(), source) if err != nil { @@ -79,7 +98,13 @@ func SyncSources() (int, error) { } fmt.Println() for _, i := range info { - fmt.Println(*i.Filename) + err = os.Link(downloadsDir + *i.Filename, keyPath + *i.Filename) + if err != nil { + if err.Error() != "link " + downloadsDir + *i.Filename + " " + keyPath + *i.Filename + ": file exists" { + return 0, err + } + } + srcCount++ } } } -- knotmirror 0.0.1