summaryrefslogtreecommitdiff
path: root/src/rhimportd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-02 13:39:54 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-02 13:39:54 (GMT)
commitc69154b5c1e35ef038f00661e66fcb90113891bf (patch)
treecd3aed7f962e10d6b9a28e49f2a614de05cda32d /src/rhimportd
parenta9e805190242f5580036ff33fe7770af34fc7681 (diff)
improved handling of time.Ticker
Diffstat (limited to 'src/rhimportd')
-rw-r--r--src/rhimportd/ctrlWatchDir.go5
-rw-r--r--src/rhimportd/uploadWeb.go14
2 files changed, 12 insertions, 7 deletions
diff --git a/src/rhimportd/ctrlWatchDir.go b/src/rhimportd/ctrlWatchDir.go
index 1b08e62..14d1c1f 100644
--- a/src/rhimportd/ctrlWatchDir.go
+++ b/src/rhimportd/ctrlWatchDir.go
@@ -165,6 +165,8 @@ func watchDirHandler(conf *rhimport.Config, db *rddb.DBChan, ctx *rhimport.Conte
func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) {
rhl.Printf("watch-dir-ctrl: watching for files in %s", dir.Name())
+ t := time.NewTicker(1 * time.Second)
+ defer t.Stop()
for {
var err error
if _, err = dir.Seek(0, 0); err != nil {
@@ -199,8 +201,7 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) {
}
}
}
-
- time.Sleep(1 * time.Second)
+ <-t.C
}
}
diff --git a/src/rhimportd/uploadWeb.go b/src/rhimportd/uploadWeb.go
index dc9b25c..1e3e7f0 100644
--- a/src/rhimportd/uploadWeb.go
+++ b/src/rhimportd/uploadWeb.go
@@ -119,7 +119,6 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport
rhl.Printf("WebUploadHandler: got request from user '%s', filename='%s'", username, hdr.Filename)
- // TODO: uploaded files should be deleted after some time... create directory with timestamp as part of the name?
dstpath, err := ioutil.TempDir(conf.TempDir, "webupload-"+username+"-")
if err != nil {
rhl.Printf("WebUploadHandler: error creating temporary directory: %v", err)
@@ -141,8 +140,9 @@ func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport
}
func webUploadCleanerRun(dir *os.File, conf *rhimport.Config) {
- t := time.Tick(5 * time.Second)
- for now := range t {
+ t := time.NewTicker(5 * time.Second)
+ defer t.Stop()
+ for now := range t.C {
var err error
if _, err = dir.Seek(0, 0); err != nil {
rhl.Printf("webUploadCleaner: reading directory contents failed: %s", err)
@@ -163,7 +163,13 @@ func webUploadCleanerRun(dir *os.File, conf *rhimport.Config) {
}
func webUploadCleaner(conf *rhimport.Config) {
+ first := true
for {
+ if !first {
+ time.Sleep(5 * time.Second)
+ }
+ first = false
+
dir, err := os.Open(conf.TempDir)
if err != nil {
rhl.Printf("webUploadCleaner: %s", err)
@@ -183,7 +189,5 @@ func webUploadCleaner(conf *rhimport.Config) {
webUploadCleanerRun(dir, conf)
rhdl.Printf("webUploadCleanerRun: returned - restring in 5 sec...")
dir.Close()
-
- time.Sleep(5 * time.Second)
}
}