diff --git a/cli/backup.go b/cli/backup.go index b5b509fa..2723892c 100644 --- a/cli/backup.go +++ b/cli/backup.go @@ -16,13 +16,16 @@ func Backup() error { ba := nod.Begin("backing up local data...") defer ba.End() - abd := vangogh_local_data.AbsBackupsDir() + abp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Backups) + if err != nil { + return err + } - if _, err := os.Stat(abd); os.IsNotExist(err) { - if err := os.MkdirAll(abd, 0755); err != nil { + if _, err := os.Stat(abp); os.IsNotExist(err) { + if err := os.MkdirAll(abp, 0755); err != nil { return ba.EndWithError(err) } } - return Export(abd) + return Export(abp) } diff --git a/cli/cleanup.go b/cli/cleanup.go index 9c6b7040..5eec4b00 100644 --- a/cli/cleanup.go +++ b/cli/cleanup.go @@ -155,7 +155,10 @@ func (cd *cleanupDelegate) Process(_ string, slug string, list vangogh_local_dat for _, unexpectedFile := range unexpectedFiles { //restore absolute from local_filename to s/slug/local_filename - absDownloadFilename := vangogh_local_data.AbsDownloadDirFromRel(filepath.Join(pDir, unexpectedFile)) + absDownloadFilename, err := vangogh_local_data.AbsDownloadDirFromRel(filepath.Join(pDir, unexpectedFile)) + if err != nil { + return csa.EndWithError(err) + } if stat, err := os.Stat(absDownloadFilename); err == nil { cd.totalBytes += stat.Size() } else if os.IsNotExist(err) { @@ -169,20 +172,28 @@ func (cd *cleanupDelegate) Process(_ string, slug string, list vangogh_local_dat prefix = "TEST" } - relDownloadFilename, err := filepath.Rel(vangogh_local_data.AbsDownloadsDir(), absDownloadFilename) + adp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Downloads) + if err != nil { + return csa.EndWithError(err) + } + + relDownloadFilename, err := filepath.Rel(adp, absDownloadFilename) if err != nil { return csa.EndWithError(err) } dft := nod.Begin(" %s %s", prefix, relDownloadFilename) if !cd.test { - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsDownloadsDir(), absDownloadFilename); err != nil { + if err := vangogh_local_data.MoveToRecycleBin(adp, absDownloadFilename); err != nil { return dft.EndWithError(err) } } dft.End() - absChecksumFile := vangogh_local_data.AbsLocalChecksumPath(absDownloadFilename) + absChecksumFile, err := vangogh_local_data.AbsLocalChecksumPath(absDownloadFilename) + if err != nil { + return csa.EndWithError(err) + } if stat, err := os.Stat(absChecksumFile); err == nil { cd.totalBytes += stat.Size() } else if os.IsNotExist(err) { @@ -191,14 +202,19 @@ func (cd *cleanupDelegate) Process(_ string, slug string, list vangogh_local_dat return csa.EndWithError(err) } - relChecksumFile, err := filepath.Rel(vangogh_local_data.AbsChecksumsDir(), absChecksumFile) + acp, err := vangogh_local_data.GetAbsRelDir(vangogh_local_data.Checksums) + if err != nil { + return csa.EndWithError(err) + } + + relChecksumFile, err := filepath.Rel(acp, absChecksumFile) if err != nil { return csa.EndWithError(err) } cft := nod.Begin(" %s %s", prefix, relChecksumFile) if !cd.test { - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsChecksumsDir(), absChecksumFile); err != nil { + if err := vangogh_local_data.MoveToRecycleBin(acp, absChecksumFile); err != nil { return cft.EndWithError(err) } } diff --git a/cli/dehydrate.go b/cli/dehydrate.go index 665c9b7d..79b0f8f6 100644 --- a/cli/dehydrate.go +++ b/cli/dehydrate.go @@ -84,7 +84,12 @@ func Dehydrate( continue } - if dhi, err := dehydrateImage(vangogh_local_data.AbsLocalImagePath(imageId), plt); err == nil { + alip, err := vangogh_local_data.AbsLocalImagePath(imageId) + if err != nil { + return di.EndWithError(err) + } + + if dhi, err := dehydrateImage(alip, plt); err == nil { dehydratedImages[id] = []string{dhi} dehydratedImageModified[id] = []string{strconv.FormatInt(time.Now().Unix(), 10)} } else { diff --git a/cli/export.go b/cli/export.go index 09051c4e..e8cade69 100644 --- a/cli/export.go +++ b/cli/export.go @@ -9,18 +9,25 @@ import ( ) func ExportHandler(_ *url.URL) error { - return Export(vangogh_local_data.AbsOutputFilesDir()) + aofp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.OutputFiles) + if err != nil { + return err + } + return Export(aofp) } func Export(to string) error { - from := vangogh_local_data.AbsMetadataDir() - root, _ := filepath.Split(from) - ea := nod.NewProgress("exporting metadata...") defer ea.End() - if err := packer.Pack(root, from, to, ea); err != nil { + amp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Metadata) + if err != nil { + return ea.EndWithError(err) + } + root, _ := filepath.Split(amp) + + if err := packer.Pack(root, amp, to, ea); err != nil { return ea.EndWithError(err) } diff --git a/cli/get_data.go b/cli/get_data.go index 125f285c..9234e830 100644 --- a/cli/get_data.go +++ b/cli/get_data.go @@ -51,9 +51,12 @@ func GetData( return nil } - hc, err := coost.NewHttpClientFromFile( - vangogh_local_data.AbsCookiePath(), - gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + return gda.EndWithError(err) + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { return gda.EndWithError(err) } diff --git a/cli/get_downloads.go b/cli/get_downloads.go index f4b860fe..37e9073b 100644 --- a/cli/get_downloads.go +++ b/cli/get_downloads.go @@ -43,7 +43,12 @@ func GetDownloads( gda := nod.NewProgress("downloading product files...") defer gda.End() - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + return gda.EndWithError(err) + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { return gda.EndWithError(err) } @@ -117,7 +122,12 @@ func (gdd *getDownloadsDelegate) Process(_, slug string, list vangogh_local_data return nil } - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + return sda.EndWithError(err) + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { return sda.EndWithError(err) } @@ -163,11 +173,17 @@ func (gdd *getDownloadsDelegate) downloadManualUrl( if localPath, ok := gdd.rxa.GetFirstVal(vangogh_local_data.LocalManualUrlProperty, dl.ManualUrl); ok { //localFilename would be a relative path for a download - s/slug, //and RelToAbs would convert this to downloads/s/slug - if _, err := os.Stat(vangogh_local_data.AbsDownloadDirFromRel(localPath)); err == nil { + addp, err := vangogh_local_data.AbsDownloadDirFromRel(localPath) + if err != nil { + return dmua.EndWithError(err) + } + if _, err := os.Stat(addp); err == nil { _, localFilename := filepath.Split(localPath) lfa := nod.Begin(" - %s", localFilename) lfa.EndWithResult("already exists") return nil + } else { + return dmua.EndWithError(err) } } } @@ -200,12 +216,26 @@ func (gdd *getDownloadsDelegate) downloadManualUrl( return dmua.EndWithError(err) } //we need to add suffix to a dir path, e.g. dlc, extras - absDir := filepath.Join(pAbsDir, dl.DirSuffix()) + dtRelDir := "" + switch dl.Type { + case vangogh_local_data.DLC: + dtRelDir, err = vangogh_local_data.GetRelDir(vangogh_local_data.DLCs) + case vangogh_local_data.Extra: + dtRelDir, err = vangogh_local_data.GetRelDir(vangogh_local_data.Extras) + } + if err != nil { + return dmua.EndWithError(err) + } + absDir := filepath.Join(pAbsDir, dtRelDir) //4 remoteChecksumPath := vangogh_local_data.RemoteChecksumPath(resolvedUrl.Path) if remoteChecksumPath != "" { - localChecksumPath := vangogh_local_data.AbsLocalChecksumPath(path.Join(absDir, filename)) + localChecksumPath, err := vangogh_local_data.AbsLocalChecksumPath(path.Join(absDir, filename)) + if err != nil { + return dmua.EndWithError(err) + } + if _, err := os.Stat(localChecksumPath); os.IsNotExist(err) { checksumDir, checksumFilename := filepath.Split(localChecksumPath) dca := nod.NewProgress(" - %s", checksumFilename) @@ -234,8 +264,8 @@ func (gdd *getDownloadsDelegate) downloadManualUrl( //6 //ProductDownloadsRelDir would return relative (to downloads/ root) dir path, e.g. s/slug pRelDir, err := vangogh_local_data.RelProductDownloadsDir(slug) - //we need to add suffix to a dir path, e.g. dlc, extras - relDir := filepath.Join(pRelDir, dl.DirSuffix()) + //we need to add suffix to a dir path, e.g. dlc, extras - using already resolved download type relative dir + relDir := filepath.Join(pRelDir, dtRelDir) if err != nil { return dmua.EndWithError(err) } diff --git a/cli/get_images.go b/cli/get_images.go index 7faa299a..4f928f28 100644 --- a/cli/get_images.go +++ b/cli/get_images.go @@ -114,7 +114,10 @@ func GetImages( urls = append(urls, srcUrls...) for _, srcUrl := range srcUrls { - dstDir := vangogh_local_data.AbsImagesDirByImageId(srcUrl.Path) + dstDir, err := vangogh_local_data.AbsImagesDirByImageId(srcUrl.Path) + if err != nil { + return mita.EndWithError(err) + } filenames = append(filenames, filepath.Join(dstDir, srcUrl.Path)) } } diff --git a/cli/get_items.go b/cli/get_items.go index dba8fbe0..77e73942 100644 --- a/cli/get_items.go +++ b/cli/get_items.go @@ -80,7 +80,11 @@ func GetItems( for _, itemUrl := range items { if u, err := url.Parse(itemUrl); err == nil { urls = append(urls, u) - filenames = append(filenames, vangogh_local_data.AbsItemPath(u.Path)) + aip, err := vangogh_local_data.AbsItemPath(u.Path) + if err != nil { + return gia.EndWithError(err) + } + filenames = append(filenames, aip) } } diff --git a/cli/get_thumbnails.go b/cli/get_thumbnails.go index a4df7dc6..fae4dbed 100644 --- a/cli/get_thumbnails.go +++ b/cli/get_thumbnails.go @@ -86,7 +86,10 @@ func GetThumbnails(idSet map[string]bool, missing bool, force bool) error { vta := nod.NewProgress(" %s %s", videoId, file) - dir := vangogh_local_data.AbsVideoThumbnailsDirByVideoId(videoId) + dir, err := vangogh_local_data.AbsVideoThumbnailsDirByVideoId(videoId) + if err != nil { + return vta.EndWithError(err) + } //get-thumbnails is not using dolo.GetSetMany unlike get-images, and is downloading //thumbnails sequentially for two main reasons: diff --git a/cli/get_videos.go b/cli/get_videos.go index 18f17e1a..9b3e009a 100644 --- a/cli/get_videos.go +++ b/cli/get_videos.go @@ -101,7 +101,10 @@ func GetVideos(idSet map[string]bool, missing bool, force bool) error { continue } - dir := vangogh_local_data.AbsVideoDirByVideoId(videoId) + dir, err := vangogh_local_data.AbsVideoDirByVideoId(videoId) + if err != nil { + return vfa.EndWithError(err) + } u, err := url.Parse(vidUrl.Url) if err != nil { diff --git a/cli/summarize.go b/cli/summarize.go index 333cbb90..2c3e0bf8 100644 --- a/cli/summarize.go +++ b/cli/summarize.go @@ -123,7 +123,12 @@ func releasedToday(rxa kvas.ReduxAssets) ([]string, error) { func publishAtom(gauginUrl string, rxa kvas.ReduxAssets, summary map[string][]string) error { - atomFile, err := os.Create(vangogh_local_data.AbsAtomFeedPath()) + afp, err := vangogh_local_data.AbsAtomFeedPath() + if err != nil { + return err + } + + atomFile, err := os.Create(afp) if err != nil { return err } diff --git a/cli/sync.go b/cli/sync.go index c979645b..48dc35d0 100644 --- a/cli/sync.go +++ b/cli/sync.go @@ -317,8 +317,13 @@ func getDetailData(pts []vangogh_local_data.ProductType, since int64) error { var skipList wits.KeyValues - if _, err := os.Stat(vangogh_local_data.AbsSkipListPath()); err == nil { - slFile, err := os.Open(vangogh_local_data.AbsSkipListPath()) + aslp, err := vangogh_local_data.AbsSkipListPath() + if err != nil { + return err + } + + if _, err := os.Stat(aslp); err == nil { + slFile, err := os.Open(aslp) if err != nil { slFile.Close() return err diff --git a/cli/tag.go b/cli/tag.go index aba0327a..69b24642 100644 --- a/cli/tag.go +++ b/cli/tag.go @@ -48,7 +48,12 @@ func Tag(idSet map[string]bool, operation, tagName string) error { } } - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + return ta.EndWithError(err) + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { return ta.EndWithError(err) } diff --git a/cli/validate.go b/cli/validate.go index 21652a29..469ba311 100644 --- a/cli/validate.go +++ b/cli/validate.go @@ -139,7 +139,10 @@ func validateManualUrl( //absolute path (given a downloads/ root) for a s/slug/local_filename, //e.g. downloads/s/slug/local_filename - absLocalFile := vangogh_local_data.AbsDownloadDirFromRel(localFile) + absLocalFile, err := vangogh_local_data.AbsDownloadDirFromRel(localFile) + if err != nil { + return mua.EndWithError(err) + } if !vangogh_local_data.IsPathSupportingValidation(absLocalFile) { mua.EndWithResult(ErrValidationNotSupported.Error()) return ErrValidationNotSupported @@ -150,7 +153,10 @@ func validateManualUrl( return ErrMissingDownload } - absChecksumFile := vangogh_local_data.AbsLocalChecksumPath(absLocalFile) + absChecksumFile, err := vangogh_local_data.AbsLocalChecksumPath(absLocalFile) + if err != nil { + return mua.EndWithError(err) + } if _, err := os.Stat(absChecksumFile); os.IsNotExist(err) { mua.EndWithResult(ErrMissingChecksum.Error()) diff --git a/cli/vet.go b/cli/vet.go index 015f17d4..d0b9bd8f 100644 --- a/cli/vet.go +++ b/cli/vet.go @@ -155,7 +155,12 @@ func Vet( } if vetOpts.oldBackups { - if err := vets.OldFiles(vangogh_local_data.AbsBackupsDir(), "backups", fix); err != nil { + abp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Backups) + if err != nil { + return sda.EndWithError(err) + } + + if err := vets.OldFiles(abp, "backups", fix); err != nil { return sda.EndWithError(err) } } @@ -200,7 +205,10 @@ func staleDehydrationsImageType(imageProperty, dimProperty string, fix bool) err for _, id := range ids { if imageId, ok := rxa.GetFirstVal(imageProperty, id); ok { - imagePath := vangogh_local_data.AbsLocalImagePath(imageId) + imagePath, err := vangogh_local_data.AbsLocalImagePath(imageId) + if err != nil { + return sdia.EndWithError(err) + } if stat, err := os.Stat(imagePath); err == nil { if dimStr, ok := rxa.GetFirstVal(dimProperty, id); ok { if dim, err := strconv.ParseInt(dimStr, 10, 64); err == nil { diff --git a/cli/vets/files_in_recycle_bin.go b/cli/vets/files_in_recycle_bin.go index df88780c..c00fd32e 100644 --- a/cli/vets/files_in_recycle_bin.go +++ b/cli/vets/files_in_recycle_bin.go @@ -29,9 +29,13 @@ func FilesInRecycleBin(fix bool) error { if fix { rfa := nod.NewProgress(" emptying recycle bin...") + rbdp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.RecycleBin) + if err != nil { + return rfa.EndWithError(err) + } rfa.TotalInt(len(recycleBinFiles)) for file := range recycleBinFiles { - if err := os.Remove(filepath.Join(vangogh_local_data.AbsRecycleBinDir(), file)); err != nil { + if err := os.Remove(filepath.Join(rbdp, file)); err != nil { return rfa.EndWithError(err) } rfa.Increment() diff --git a/cli/vets/invalid_resolved_manual_urls.go b/cli/vets/invalid_resolved_manual_urls.go index e7669744..43b88944 100644 --- a/cli/vets/invalid_resolved_manual_urls.go +++ b/cli/vets/invalid_resolved_manual_urls.go @@ -53,6 +53,11 @@ func InvalidResolvedManualUrls(fix bool) error { firmu.TotalInt(len(invalidResolvedUrls)) } + adp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Downloads) + if err != nil { + return cirmu.EndWithError(err) + } + for url := range invalidResolvedUrls { local, _ := rxa.GetFirstVal(vangogh_local_data.LocalManualUrlProperty, url) summary[url] = []string{local} @@ -63,8 +68,11 @@ func InvalidResolvedManualUrls(fix bool) error { } // move local file to the recycle bin - absLocalFilepath := vangogh_local_data.AbsDownloadDirFromRel(local) - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsDownloadsDir(), absLocalFilepath); err != nil { + absLocalFilepath, err := vangogh_local_data.AbsDownloadDirFromRel(local) + if err != nil { + cirmu.Error(err) + } + if err := vangogh_local_data.MoveToRecycleBin(adp, absLocalFilepath); err != nil { cirmu.Error(err) } if firmu != nil { diff --git a/cli/vets/local_only_images.go b/cli/vets/local_only_images.go index 9dd25b82..58c18b45 100644 --- a/cli/vets/local_only_images.go +++ b/cli/vets/local_only_images.go @@ -70,14 +70,22 @@ func LocalOnlyImages(fix bool) error { loia.EndWithResult("found %d unexpected images", len(unexpectedImages)) + aip, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Images) + if err != nil { + return loia.EndWithError(err) + } + if fix && len(unexpectedImages) > 0 { floia := nod.NewProgress(" removing %d local only image(s)...", len(unexpectedImages)) floia.TotalInt(len(unexpectedImages)) for _, imageId := range unexpectedImages { - absLocalImagePath := vangogh_local_data.AbsLocalImagePath(imageId) + absLocalImagePath, err := vangogh_local_data.AbsLocalImagePath(imageId) + if err != nil { + return floia.EndWithError(err) + } nod.Log("removing local only imageId=%s file=%s", imageId, absLocalImagePath) - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsImagesDir(), absLocalImagePath); err != nil && !os.IsNotExist(err) { + if err := vangogh_local_data.MoveToRecycleBin(aip, absLocalImagePath); err != nil && !os.IsNotExist(err) { return floia.EndWithError(err) } floia.Increment() diff --git a/cli/vets/local_only_videos_and_thumbnails.go b/cli/vets/local_only_videos_and_thumbnails.go index 17df6d4b..5b17f660 100644 --- a/cli/vets/local_only_videos_and_thumbnails.go +++ b/cli/vets/local_only_videos_and_thumbnails.go @@ -63,15 +63,31 @@ func LocalOnlyVideosAndThumbnails(fix bool) error { flova := nod.NewProgress(" removing %d local only video(s)...", len(unexpectedVideos)) flova.TotalInt(len(unexpectedVideos)) + avp, err := vangogh_local_data.GetAbsDir(vangogh_local_data.Videos) + if err != nil { + return flova.EndWithError(err) + } + + avtp, err := vangogh_local_data.GetAbsRelDir(vangogh_local_data.VideoThumbnails) + if err != nil { + return flova.EndWithError(err) + } + for _, videoId := range unexpectedVideos { - absLocalVideoPath := vangogh_local_data.AbsLocalVideoPath(videoId) + absLocalVideoPath, err := vangogh_local_data.AbsLocalVideoPath(videoId) + if err != nil { + return flova.EndWithError(err) + } nod.Log("removing local only videoId=%s file=%s", videoId, absLocalVideoPath) - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsVideosDir(), absLocalVideoPath); err != nil && !os.IsNotExist(err) { + if err := vangogh_local_data.MoveToRecycleBin(avp, absLocalVideoPath); err != nil && !os.IsNotExist(err) { + return flova.EndWithError(err) + } + absLocalThumbnailPath, err := vangogh_local_data.AbsLocalVideoThumbnailPath(videoId) + if err != nil { return flova.EndWithError(err) } - absLocalThumbnailPath := vangogh_local_data.AbsLocalVideoThumbnailPath(videoId) nod.Log("removing local only thumbnail videoId=%s file=%s", videoId, absLocalThumbnailPath) - if err := vangogh_local_data.MoveToRecycleBin(vangogh_local_data.AbsVideoThumbnailsDir(), absLocalThumbnailPath); err != nil && !os.IsNotExist(err) { + if err := vangogh_local_data.MoveToRecycleBin(avtp, absLocalThumbnailPath); err != nil && !os.IsNotExist(err) { return flova.EndWithError(err) } flova.Increment() diff --git a/cli/vets/missing_checksums.go b/cli/vets/missing_checksums.go index cbcecf3b..ac930c2b 100644 --- a/cli/vets/missing_checksums.go +++ b/cli/vets/missing_checksums.go @@ -68,7 +68,10 @@ func MissingChecksums(fix bool) error { continue } - absChecksumFile := vangogh_local_data.AbsLocalChecksumPath(relFile) + absChecksumFile, err := vangogh_local_data.AbsLocalChecksumPath(relFile) + if err != nil { + return mca.EndWithError(err) + } if _, err := os.Stat(absChecksumFile); os.IsNotExist(err) { filesMissingChecksums[relFile] = nil } @@ -87,7 +90,10 @@ func MissingChecksums(fix bool) error { gca.Error(err) } - absChecksum := vangogh_local_data.AbsLocalChecksumPath(relFile) + absChecksum, err := vangogh_local_data.AbsLocalChecksumPath(relFile) + if err != nil { + return gca.EndWithError(err) + } checksumFile, err := os.Create(absChecksum) if err != nil { @@ -114,7 +120,10 @@ func generateChecksumData(relFile string) (*vangogh_local_data.ValidationFile, e fa := nod.NewProgress(" %s", fname) defer fa.End() - absFile := vangogh_local_data.AbsDownloadDirFromRel(relFile) + absFile, err := vangogh_local_data.AbsDownloadDirFromRel(relFile) + if err != nil { + return nil, fa.EndWithError(err) + } inputFile, err := os.Open(absFile) if err != nil { diff --git a/cli/wishlist.go b/cli/wishlist.go index 1795a049..49a36430 100644 --- a/cli/wishlist.go +++ b/cli/wishlist.go @@ -19,7 +19,12 @@ func Wishlist(addProductIds, removeProductIds []string) error { wa := nod.Begin("performing requested wishlist operations...") defer wa.End() - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + return wa.EndWithError(err) + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { return wa.EndWithError(err) } diff --git a/go.mod b/go.mod index 6e47549a..ba4f62e2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/arelate/southern_light v0.1.28 - github.com/arelate/vangogh_local_data v0.2.99 + github.com/arelate/vangogh_local_data v0.3.1 github.com/boggydigital/atomus v0.1.9 github.com/boggydigital/clo v0.3.6 github.com/boggydigital/coost v0.3.8 diff --git a/go.sum b/go.sum index 451adf6a..1c40e85c 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,10 @@ github.com/arelate/vangogh_local_data v0.2.98 h1:3otNVc9lXpZKy/rQnWhasHLhAFSr/S6 github.com/arelate/vangogh_local_data v0.2.98/go.mod h1:LAN01fnSbM2BKqAnWv6+/0yB3S4QkczNzjVc+/4FanQ= github.com/arelate/vangogh_local_data v0.2.99 h1:PUlKW5kyYtDhpDAlXAvg3QwVRmgCSyDcYy/q69SeeA4= github.com/arelate/vangogh_local_data v0.2.99/go.mod h1:LAN01fnSbM2BKqAnWv6+/0yB3S4QkczNzjVc+/4FanQ= +github.com/arelate/vangogh_local_data v0.3.0 h1:GqgoZtZwVMJu5LvEyUdbyn+f5x3gxL/rGfVJ/0p00To= +github.com/arelate/vangogh_local_data v0.3.0/go.mod h1:LAN01fnSbM2BKqAnWv6+/0yB3S4QkczNzjVc+/4FanQ= +github.com/arelate/vangogh_local_data v0.3.1 h1:MXTWVxNqCTKpCZhdLjCnAa7jzrIrhEQ/HldC3KHYEzw= +github.com/arelate/vangogh_local_data v0.3.1/go.mod h1:LAN01fnSbM2BKqAnWv6+/0yB3S4QkczNzjVc+/4FanQ= github.com/boggydigital/atomus v0.1.9 h1:zAmXtAAXtBzMfz/83nEO4x8/uSLlPOq5wynW1jR/rbk= github.com/boggydigital/atomus v0.1.9/go.mod h1:mvPDNDMrpFZ7RHbyMrt30hVXFU+VoeCvHnT83Zhj91I= github.com/boggydigital/clo v0.3.6 h1:syeucZIM2/9B3jsUZqDo3TOYqgvJ6C1ketRgSuDoUf4= diff --git a/main.go b/main.go index c169dd71..581c6553 100644 --- a/main.go +++ b/main.go @@ -27,23 +27,22 @@ var ( ) const ( - directoriesFilename = "directories.txt" + userDirsFilename = "directories.txt" + defaultRootDir = "/var/lib/vangogh" ) -var ( - rootDir = "/var/lib/vangogh" - - backupsDir = rootDir + "/backups" - downloadsDir = rootDir + "/downloads" - imagesDir = rootDir + "/images" - inputFilesDir = rootDir - outputFilesDir = rootDir - itemsDir = rootDir + "/items" - logsDir = "/var/log/vangogh" - metadataDir = rootDir + "/metadata" - recycleBinDir = "/var/tmp" - videosDir = rootDir + "/videos" -) +var defaultDirs = map[string]string{ + "backups": defaultRootDir + "/backups", + "downloads": defaultRootDir + "/downloads", + "images": defaultRootDir + "/images", + "input_files": defaultRootDir, + "items": defaultRootDir + "/items", + "logs": "/var/log/vangogh", + "metadata": defaultRootDir + "/metadata", + "output_files": defaultRootDir, + "recycle_bin": defaultRootDir + "/recycle_bin", + "videos": defaultRootDir + "/videos", +} func main() { @@ -52,24 +51,11 @@ func main() { ns := nod.Begin("vangogh is serving your DRM-free needs") defer ns.End() - if err := readUserDirectories(); err != nil { + if err := chRoot(userDirsFilename, defaultDirs); err != nil { _ = ns.EndWithError(err) os.Exit(1) } - //set directories context in vangogh_cli_api - //vangogh_local_data.SetTempDir(tempDir) - //vangogh_local_data.ChRoot(rootDir) - vangogh_local_data.SetBackupsDir(backupsDir) - vangogh_local_data.SetDownloadsDir(downloadsDir) - vangogh_local_data.SetImagesDir(imagesDir) - vangogh_local_data.SetInputFilesDir(inputFilesDir) - vangogh_local_data.SetItemsDir(itemsDir) - vangogh_local_data.SetMetadataDir(metadataDir) - vangogh_local_data.SetRecycleBinDir(recycleBinDir) - vangogh_local_data.SetVideosDir(videosDir) - dirs.SetLogsDir(logsDir) - defs, err := clo.Load( bytes.NewBuffer(cliCommands), bytes.NewBuffer(cliHelp), @@ -118,128 +104,33 @@ func main() { os.Exit(1) } - //debug code to print out all Unity games that provide Linux releases, and no macOS releases - // - //fmt.Print() - // - //rxa, err := vangogh_local_data.ConnectReduxAssets(vangogh_local_data.ReduxProperties()...) - //if err != nil { - // panic(err) - //} - // - //for _, id := range rxa.Keys(vangogh_local_data.TitleProperty) { - // - // isUnity := false - // engines, _ := rxa.GetAllValues(vangogh_local_data.EnginesProperty, id) - // for _, engine := range engines { - // isUnity = isUnity || strings.Contains(engine, "Unity") - // } - // - // if !isUnity { - // continue - // } - // - // oss, _ := rxa.GetAllValues(vangogh_local_data.OperatingSystemsProperty, id) - // linuxStr, macOSStr := strings.ToLower(vangogh_local_data.Linux.String()), strings.ToLower(vangogh_local_data.MacOS.String()) - // if !slices.Contains(oss, linuxStr) || slices.Contains(oss, macOSStr) { - // continue - // } - // - // productType, _ := rxa.GetFirstVal(vangogh_local_data.ProductTypeProperty, id) - // if productType != "GAME" { - // continue - // } - // - // title, _ := rxa.GetFirstVal(vangogh_local_data.TitleProperty, id) - // - // fmt.Println(id, title) - //} - // - //return - if err := defs.Serve(os.Args[1:]); err != nil { _ = ns.EndWithError(err) os.Exit(1) } } -func readUserDirectories() error { - if _, err := os.Stat(directoriesFilename); os.IsNotExist(err) { - return nil - } +func chRoot(userDirsFilename string, defaultDirs map[string]string) error { - udFile, err := os.Open(directoriesFilename) - if err != nil { - return err - } + var userDirs map[string]string - dirs, err := wits.ReadKeyValue(udFile) - if err != nil { - return err - } - - if bd, ok := dirs["backups"]; ok { - backupsDir = bd - } - if dd, ok := dirs["downloads"]; ok { - downloadsDir = dd - } - if imd, ok := dirs["images"]; ok { - imagesDir = imd - } - if ifd, ok := dirs["input_files"]; ok { - inputFilesDir = ifd - } - if itd, ok := dirs["items"]; ok { - itemsDir = itd - } - if ld, ok := dirs["logs"]; ok { - logsDir = ld - } - if md, ok := dirs["metadata"]; ok { - metadataDir = md - } - if ofd, ok := dirs["output_files"]; ok { - outputFilesDir = ofd - } - if rbd, ok := dirs["recycle_bin"]; ok { - recycleBinDir = rbd - } - if vd, ok := dirs["videos"]; ok { - videosDir = vd - } + if _, err := os.Stat(userDirsFilename); err == nil { + udFile, err := os.Open(userDirsFilename) + if err != nil { + return err + } - //validate that directories actually exist - if _, err := os.Stat(backupsDir); err != nil { - return err - } - if _, err := os.Stat(downloadsDir); err != nil { - return err - } - if _, err := os.Stat(imagesDir); err != nil { - return err - } - if _, err := os.Stat(inputFilesDir); err != nil { - return err - } - if _, err := os.Stat(itemsDir); err != nil { - return err - } - if _, err := os.Stat(logsDir); err != nil { - return err - } - if _, err := os.Stat(metadataDir); err != nil { - return err - } - if _, err := os.Stat(outputFilesDir); err != nil { - return err - } - if _, err := os.Stat(recycleBinDir); err != nil { - return err - } - if _, err := os.Stat(videosDir); err != nil { + userDirs, err = wits.ReadKeyValue(udFile) + if err != nil { + return err + } + } else if os.IsNotExist(err) { + userDirs = defaultDirs + } else { return err } - return nil + dirs.SetLogsDir(userDirs["logs"]) + + return vangogh_local_data.SetAbsDirs(userDirs) } diff --git a/rest/get_atom.go b/rest/get_atom.go index 1656a2b6..c08a5da2 100644 --- a/rest/get_atom.go +++ b/rest/get_atom.go @@ -13,7 +13,12 @@ func GetAtom(w http.ResponseWriter, r *http.Request) { // GET /atom - absAtomFeedPath := vangogh_local_data.AbsAtomFeedPath() + absAtomFeedPath, err := vangogh_local_data.AbsAtomFeedPath() + if err != nil { + http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) + return + } + if stat, err := os.Stat(absAtomFeedPath); err == nil { w.Header().Set(middleware.LastModifiedHeader, stat.ModTime().UTC().Format(http.TimeFormat)) diff --git a/rest/patch_tag.go b/rest/patch_tag.go index bd7daf71..959e94b7 100644 --- a/rest/patch_tag.go +++ b/rest/patch_tag.go @@ -21,7 +21,13 @@ func PatchTag(w http.ResponseWriter, r *http.Request) { return } - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) + return + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) return diff --git a/rest/route_wishlist.go b/rest/route_wishlist.go index 72a3c5dd..a68433b5 100644 --- a/rest/route_wishlist.go +++ b/rest/route_wishlist.go @@ -16,7 +16,13 @@ func RouteWishlist(w http.ResponseWriter, r *http.Request) { return } - hc, err := coost.NewHttpClientFromFile(vangogh_local_data.AbsCookiePath(), gog_integration.GogHost) + acp, err := vangogh_local_data.AbsCookiePath() + if err != nil { + http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) + return + } + + hc, err := coost.NewHttpClientFromFile(acp, gog_integration.GogHost) if err != nil { http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError) return