diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-08-04 03:20:07 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-08-04 03:20:07 (GMT) |
commit | 6107b08a3f4f66bcbb5da9a84b43f19030d0fbc6 (patch) | |
tree | 7624cc2c2a1298b4c3509d73dfbb89d2863888b7 | |
parent | 6c795d0c55512f43ba14b9f4e4451574aa5b3700 (diff) |
file policy should work now - need testing
-rw-r--r-- | rhimport/session.go | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/rhimport/session.go b/rhimport/session.go index 7699efc..1e6b329 100644 --- a/rhimport/session.go +++ b/rhimport/session.go @@ -27,6 +27,7 @@ package rhimport import ( "fmt" "net/http" + "strings" "time" ) @@ -105,45 +106,49 @@ func sessionProgressCallback(step int, stepName string, current, total float64, return true } -func sessionRun(ctx Context, done chan<- Result) { - err := ctx.SanityCheck() +func (s *session) runner() { + err := s.ctx.SanityCheck() if err != nil { - done <- Result{ResponseCode: http.StatusBadRequest, ErrorString: err.Error()} + s.doneIntChan <- Result{ResponseCode: http.StatusBadRequest, ErrorString: err.Error()} return } var res *Result - res, err = FetchFile(&ctx) + res, err = FetchFile(&s.ctx) if err != nil { - done <- Result{ResponseCode: http.StatusInternalServerError, ErrorString: err.Error()} + s.doneIntChan <- Result{ResponseCode: http.StatusInternalServerError, ErrorString: err.Error()} return } if res.ResponseCode != http.StatusOK { - done <- *res + s.doneIntChan <- *res return } - if res, err = NormalizeFile(&ctx); err != nil { - done <- Result{ResponseCode: http.StatusInternalServerError, ErrorString: err.Error()} + if res, err = NormalizeFile(&s.ctx); err != nil { + s.doneIntChan <- Result{ResponseCode: http.StatusInternalServerError, ErrorString: err.Error()} return } if res.ResponseCode != http.StatusOK { - done <- *res + s.doneIntChan <- *res return } - if res, err = ImportFile(&ctx); err != nil { + if s.ctx.SourceFilePolicy == Keep { + s.removeWorkDir = false + } + if res, err = ImportFile(&s.ctx); err != nil { res.ResponseCode = http.StatusInternalServerError res.ErrorString = err.Error() } - done <- *res + res.SourceFile = "tmp://" + strings.TrimPrefix(s.ctx.SourceFile, s.ctx.conf.TempDir) + s.doneIntChan <- *res } func (s *session) run(timeout time.Duration) { s.ctx.ProgressCallBack = sessionProgressCallback s.ctx.ProgressCallBackData = (chan<- ProgressData)(s.progressIntChan) s.ctx.Cancel = s.cancelIntChan - go sessionRun(s.ctx, s.doneIntChan) + go s.runner() s.state = _SESSION_RUNNING if timeout <= 0 || timeout > 3*time.Hour { s.ctx.stdlog.Printf("requested session timeout (%v) is invalid or too high - setting it to 3h", timeout) @@ -208,27 +213,6 @@ 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) -// if err := os.Remove(ctx.SourceFile); err != nil { -// ctx.stdlog.Printf("importer: error removing source file: %s", err) -// return -// } -// if ctx.DeleteSourceDir { -// dir := path.Dir(ctx.SourceFile) -// ctx.dbglog.Printf("importer: also removing directory: %s", dir) -// if err := os.Remove(dir); err != nil { -// ctx.stdlog.Printf("importer: error removing source directory: %s", err) -// } -// } -// } else { -// res.SourceFile = "tmp://" + strings.TrimPrefix(ctx.SourceFile, ctx.conf.TempDir) -// } -// return -// } - func (s *session) dispatchRequests() { defer func() { if s.cancelUploader != nil { @@ -294,7 +278,6 @@ 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() |