Skip to content

Commit

Permalink
Fix cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
tonimelisma committed Dec 11, 2020
1 parent 7009826 commit ae5f6c1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
},
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 958283
},
]
}
40 changes: 25 additions & 15 deletions cmd/fastgallery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,19 +834,16 @@ func main() {
}
fmt.Println("")

// create gallery directory if it doesn't exist
createDirectory(outputDirectory)

// check that source directory doesn't have reserved directory or file names
checkReservedNames(inputDirectory)

// create directory structs by recursing through source and gallery directories
if _, err := os.Stat(outputDirectory); os.IsNotExist(err) {
// gallery.name = filepath.Base(outputDirectory)
// gallery.absPath, _ = filepath.Abs(outputDirectory)
// gallery.relPath = ""
} else {
if _, err := os.Stat(outputDirectory); !os.IsNotExist(err) {
gallery = recurseDirectory(outputDirectory, "")
} else {
gallery.name = filepath.Base(outputDirectory)
gallery.absPath, _ = filepath.Abs(outputDirectory)
gallery.relPath = ""
}
source = recurseDirectory(inputDirectory, "")

Expand All @@ -872,8 +869,17 @@ func main() {
if changes > 0 {
if optCleanUp {
fmt.Print("Cleaning up unused media files in output directory...")
cleanGallery(gallery)
fmt.Println("done.")
if _, err := os.Stat(gallery.absPath); !os.IsNotExist(err) {
cleanGallery(gallery)
fmt.Println("done.")
} else {
fmt.Println("already empty.")
}
}

// create gallery directory if it doesn't exist
if _, err := os.Stat(gallery.absPath); os.IsNotExist(err) {
createDirectory(gallery.absPath)
}

var progressBar *pb.ProgressBar
Expand All @@ -885,14 +891,18 @@ func main() {
} else {
vips.LoggingSettings(nil, vips.LogLevelMessage)
}
vips.Startup(nil)
vips.Startup(&vips.Config{
MaxCacheFiles: 0,
MaxCacheMem: 0,
MaxCacheSize: 0,
ReportLeaks: false})
defer vips.Shutdown()
}

fullsizeImageJobs := make(chan job, 100000)
thumbnailImageJobs := make(chan job, 100000)
fullsizeVideoJobs := make(chan job, 100000)
thumbnailVideoJobs := make(chan job, 100000)
fullsizeImageJobs := make(chan job, 10000)
thumbnailImageJobs := make(chan job, 10000)
fullsizeVideoJobs := make(chan job, 10000)
thumbnailVideoJobs := make(chan job, 10000)

var wg sync.WaitGroup

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ go 1.15

require (
github.com/cheggaaa/pb/v3 v3.0.5
github.com/davidbyttow/govips/v2 v2.1.1-0.20201208200022-af2246fbafa8
github.com/davidbyttow/govips/v2 v2.1.1-0.20201210220308-63f6534b5fe1
github.com/fatih/color v1.10.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
golang.org/x/net v0.0.0-20201207224615-747e23833adb // indirect
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1 // indirect
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
17 changes: 7 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ github.com/cheggaaa/pb/v3 v3.0.5/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+Yv
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidbyttow/govips/v2 v2.0.3-0.20201110212606-9418e4e2de8b h1:3G5u3xPPMJ/IN4dgnWG6GH68mDOmVlKRqxy5m/YdkLg=
github.com/davidbyttow/govips/v2 v2.0.3-0.20201110212606-9418e4e2de8b/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/davidbyttow/govips/v2 v2.1.0 h1:n18SBq7dnjvW1+WKk65tnuF9IBaA4A1YHYrQ1iKZ28g=
github.com/davidbyttow/govips/v2 v2.1.0/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/davidbyttow/govips/v2 v2.1.1-0.20201208200022-af2246fbafa8 h1:LCkxo9DUCTeYd+D2CpxXy20ngrrqDO2u+z0J3fWRo/c=
github.com/davidbyttow/govips/v2 v2.1.1-0.20201208200022-af2246fbafa8/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/davidbyttow/govips/v2 v2.1.1-0.20201210220308-63f6534b5fe1 h1:Z+LDD8N8J7C08ZJ/ScZKM8+zdOROUKajBEHaJQQw3KI=
github.com/davidbyttow/govips/v2 v2.1.1-0.20201210220308-63f6534b5fe1/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
Expand Down Expand Up @@ -45,17 +41,18 @@ golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+o
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201207224615-747e23833adb h1:xj2oMIbduz83x7tzglytWT7spn6rP+9hvKjTpro6/pM=
golang.org/x/net v0.0.0-20201207224615-747e23833adb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 h1:lwlPPsmjDKK0J6eG6xDWd5XPehI0R024zxjDnw3esPA=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1 h1:a/mKvvZr9Jcc8oKfcmgzyp7OwF73JPWsQLvH1z2Kxck=
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
Expand Down

0 comments on commit ae5f6c1

Please sign in to comment.