summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-08-04 01:59:23 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-08-04 01:59:23 (GMT)
commit6c795d0c55512f43ba14b9f4e4451574aa5b3700 (patch)
tree101ac04e871771458213a6e3f6045702b1fbb3db
parent9d1a296bb18bd343f133326bd2eb4b2b3368bf65 (diff)
simplified SourceFilePolicy - not done yet
-rw-r--r--rhimport/core.go25
-rw-r--r--rhimport/session.go9
2 files changed, 14 insertions, 20 deletions
diff --git a/rhimport/core.go b/rhimport/core.go
index dae4b34..2acec51 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -84,38 +84,28 @@ type Result struct {
type FilePolicy int
const (
- Auto FilePolicy = iota
+ Delete FilePolicy = iota
Keep
- Delete
- DeleteWithDir
)
func (p *FilePolicy) String() string {
switch *p {
- case Auto:
- return "auto"
- case Keep:
- return "keep"
case Delete:
return "delete"
- case DeleteWithDir:
- return "delete-with-dir"
+ case Keep:
+ return "keep"
}
return "unknown"
}
func (p *FilePolicy) FromString(str string) error {
switch str {
- case "auto":
- *p = Auto
- case "keep":
- *p = Keep
case "delete":
*p = Delete
- case "delete-with-dir":
- *p = DeleteWithDir
+ case "keep":
+ *p = Keep
default:
- return fmt.Errorf("must be on of: auto, keep, delete or delete-with-dir")
+ return fmt.Errorf("must be on of: auto, keep, delete")
}
return nil
}
@@ -202,7 +192,7 @@ func NewContext(conf *Config, db *rddb.DB, stdlog, dbglog *log.Logger) *Context
ctx.Title = ""
ctx.SourceFile = ""
ctx.LoudnessCorr = 0.0
- ctx.SourceFilePolicy = Auto
+ ctx.SourceFilePolicy = Delete
ctx.ProgressCallBack = nil
ctx.Cancel = nil
@@ -270,7 +260,6 @@ func (ctx *Context) CreateTempWorkDir() (err error) {
}
func (ctx *Context) RemoveTempWorkDir() {
- // check File Policy!!!
if err := os.RemoveAll(ctx.WorkDir); err != nil {
ctx.stdlog.Printf("Error removing WorkDir: %s", err)
}
diff --git a/rhimport/session.go b/rhimport/session.go
index 993575a..7699efc 100644
--- a/rhimport/session.go
+++ b/rhimport/session.go
@@ -96,6 +96,7 @@ type session struct {
progressCBs []*sessionProgressCB
doneCBs []*sessionDoneCB
cancelUploader chan bool
+ removeWorkDir bool
}
func sessionProgressCallback(step int, stepName string, current, total float64, title string, cart, cut uint, userdata interface{}) bool {
@@ -207,6 +208,7 @@ func (s *session) attachUploader() (resp attachUploaderResponse) {
return
}
+// TODO: see handler for doneIntChan...
// func cleanupFiles(ctx *Context, res *Result) {
// if ctx.DeleteSourceFile {
// ctx.dbglog.Printf("importer: removing file: %s", ctx.SourceFile)
@@ -292,6 +294,7 @@ func (s *session) dispatchRequests() {
if s.state != _SESSION_TIMEOUT {
s.timer.Stop()
s.state = _SESSION_DONE
+ // TODO handle SourceFilePolicy == keep!!!
s.callDoneHandler(&r)
if s.removeFunc != nil {
s.removeFunc()
@@ -405,7 +408,9 @@ func (s *session) cleanup() {
// close(s.addProgressChan)
// close(s.addDoneChan)
// close(s.attachUploader)
- s.ctx.RemoveTempWorkDir()
+ if s.removeWorkDir {
+ s.ctx.RemoveTempWorkDir()
+ }
s.ctx.dbglog.Printf("Session: cleanup is now done")
}
@@ -417,7 +422,7 @@ func newSession(ctx *Context, removeFunc func()) (s *session, err error) {
if err = s.ctx.CreateTempWorkDir(); err != nil {
return
}
-
+ s.removeWorkDir = true
s.quit = make(chan bool, 1)
s.done = make(chan bool)
s.timer = time.NewTimer(10 * time.Second)