diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-12-09 01:32:32 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-12-09 01:57:20 +0100 |
commit | 5c6a5b3ec2e820ec75c51ff025624520f714bb1e (patch) | |
tree | 69bd2f9490b9d77860ac22142f3e97a9792f3566 /main.go | |
parent | 3c299f237d96a4fd3154fb4893525622c6bb673a (diff) | |
download | gallery-5c6a5b3ec2e820ec75c51ff025624520f714bb1e.tar.gz gallery-5c6a5b3ec2e820ec75c51ff025624520f714bb1e.tar.xz gallery-5c6a5b3ec2e820ec75c51ff025624520f714bb1e.zip |
Add a test
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -27,7 +27,8 @@ var ( func openDB(directory string) error { var err error - db, err = sql.Open("sqlite3", filepath.Join(directory, "gallery.db")) + db, err = sql.Open("sqlite3", + "file:"+filepath.Join(directory, "gallery.db?_foreign_keys=1")) gd = directory return err } @@ -77,10 +78,10 @@ func cmdInit(args []string) { // XXX: There's technically no reason to keep images as symlinks, // we might just keep absolute paths in the database as well. - if err := os.MkdirAll(filepath.Join(gd, "images"), 0777); err != nil { + if err := os.MkdirAll(filepath.Join(gd, "images"), 0755); err != nil { log.Fatalln(err) } - if err := os.MkdirAll(filepath.Join(gd, "thumbs"), 0777); err != nil { + if err := os.MkdirAll(filepath.Join(gd, "thumbs"), 0755); err != nil { log.Fatalln(err) } } @@ -180,10 +181,10 @@ func importFunc(path string, d fs.DirEntry, err error) error { return err } - hexSHA1 := hex.EncodeToString(hash.Sum(make([]byte, sha1.Size))) + hexSHA1 := hex.EncodeToString(hash.Sum(nil)) pathImage := imagePath(hexSHA1) imageDirname, _ := filepath.Split(pathImage) - if err := os.MkdirAll(imageDirname, 755); err != nil { + if err := os.MkdirAll(imageDirname, 0755); err != nil { return err } if err := os.Symlink(absPath, pathImage); err != nil && @@ -210,6 +211,7 @@ func cmdImport(args []string) { } // TODO: This would better be done in parallel (making hashes). + // TODO: Show progress in some manner. Perhaps port my propeller code. for _, name := range args[1:] { if err := filepath.WalkDir(name, importFunc); err != nil { log.Fatalln(err) @@ -244,7 +246,7 @@ func cmdCheck(args []string) { func makeThumbnail(pathImage, pathThumb string) (int, int, error) { thumbDirname, _ := filepath.Split(pathThumb) - if err := os.MkdirAll(thumbDirname, 755); err != nil { + if err := os.MkdirAll(thumbDirname, 0755); err != nil { return 0, 0, err } @@ -285,7 +287,7 @@ func cmdThumbnail(args []string) { if len(hexSHA1) == 0 { // Get all unique images in the database with no thumbnail. var err error - hexSHA1, err = dbCollect(`SELECT DISTINCT sha1 FROM entry + hexSHA1, err = dbCollect(`SELECT DISTINCT entry.sha1 FROM entry LEFT OUTER JOIN image ON entry.sha1 = image.sha1 WHERE thumbw IS NULL OR thumbh IS NULL`) if err != nil { |