summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport')
-rw-r--r--rhimport/session.go51
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()