pull/3/head
Toni Melisma 3 years ago
parent 40b9b3f5a0
commit 0f9b3bb89f
No known key found for this signature in database
GPG Key ID: FFF9A7EDDEA34756

@ -306,6 +306,8 @@ func stripExtension(filename string) string {
return filename[0 : len(filename)-len(extension)]
}
// reservedDirectory takes a path and checks whether it's a reserved name,
// i.e. one of the internal directories used by fastgallery
func reservedDirectory(path string, config configuration) bool {
if path == config.files.thumbnailDir {
return true
@ -325,7 +327,7 @@ func reservedDirectory(path string, config configuration) bool {
// hasDirectoryChanged checks whether the gallery directory has changed and thus
// the HTML file needs to be updated. Could be due to:
// At least one non-existent source file or directory (will be created in gallery)
// We're doing a cleanup, and at least one non-existent gallery file or directory (will be removed from gallery HTML)
// We're doing a cleanup, and at least one non-existent gallery file or directory (will be removed from gallery)
func hasDirectoryChanged(source directory, gallery directory, cleanUp bool) bool {
for _, sourceFile := range source.files {
if !sourceFile.exists {
@ -372,7 +374,9 @@ func compareDirectoryTrees(source *directory, gallery *directory, config configu
var thumbnailFile, fullsizeFile, originalFile *file
// Go through all subdirectories, and check the ones that match
// the thumbnail, full-size or original subdirectories
// the thumbnail, full-size or original subdirectories.
// Simultaneously, mark any gallery files which exist in source,
// so any clean-up doesn't inadvertently delete them.
for h, subDir := range gallery.subdirectories {
if subDir.name == config.files.thumbnailDir {
for i, outputFile := range gallery.subdirectories[h].files {

@ -3,6 +3,7 @@ package main
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
@ -312,6 +313,12 @@ func TestCreateDirectoryTree(t *testing.T) {
defer emptyFile5.Close()
defer os.RemoveAll(tempDir + "/gallery/" + myConfig.files.thumbnailDir + "/file.jpg")
// Ensure thumbnail file is newer than source file
err = os.Chtimes(tempDir+"/gallery/"+myConfig.files.thumbnailDir+"/file.jpg", time.Now(), time.Now())
if err != nil {
t.Error("couldn't change mtime/atime")
}
emptyFile6, err := os.Create(tempDir + "/gallery/" + myConfig.files.fullsizeDir + "/file.jpg")
if err != nil {
t.Error("couldn't create original gallery file")
@ -323,6 +330,8 @@ func TestCreateDirectoryTree(t *testing.T) {
gallery := createDirectoryTree(tempDir+"/gallery", "")
compareDirectoryTrees(&source, &gallery, myConfig)
t.Log(source)
t.Log(gallery)
changes := countChanges(source)

Loading…
Cancel
Save