aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/main.go b/main.go
index fc19dd6..09ff161 100644
--- a/main.go
+++ b/main.go
@@ -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 {