summaryrefslogtreecommitdiff
path: root/src/rhimportd/ctrlWatchDir.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-03-11 18:55:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-03-11 18:55:59 (GMT)
commitabe9916c72d1e5ab282f9fde26948e6d74bfb266 (patch)
tree06a096deb4f63e2b986a32e383e0fd03e19c9df7 /src/rhimportd/ctrlWatchDir.go
parentff37f7cf351287ff6d20f197e2ff2fa2401470cc (diff)
added support for filepolicy to telnet and watchdir control
Diffstat (limited to 'src/rhimportd/ctrlWatchDir.go')
-rw-r--r--src/rhimportd/ctrlWatchDir.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/rhimportd/ctrlWatchDir.go b/src/rhimportd/ctrlWatchDir.go
index 7290597..7ab0a12 100644
--- a/src/rhimportd/ctrlWatchDir.go
+++ b/src/rhimportd/ctrlWatchDir.go
@@ -49,6 +49,7 @@ type watchDirRequestData struct {
AutotrimLevel int `json:"AUTOTRIM_LEVEL"`
UseMetaData bool `json:"USE_METADATA"`
SourceUri string `json:"SOURCE_URI"`
+ SourceFilePolicy string `json:"SOURCE_FILE_POLICY"`
}
func newWatchDirRequestData(conf *rhimport.Config) *watchDirRequestData {
@@ -65,6 +66,7 @@ func newWatchDirRequestData(conf *rhimport.Config) *watchDirRequestData {
rd.AutotrimLevel = conf.ImportParamDefaults.AutotrimLevel
rd.UseMetaData = conf.ImportParamDefaults.UseMetaData
rd.SourceUri = ""
+ rd.SourceFilePolicy = ""
return rd
}
@@ -74,6 +76,7 @@ type watchDirResponseData struct {
ErrorString string `json:"ERROR_STRING"`
Cart uint `json:"CART_NUMBER"`
Cut uint `json:"CUT_NUMBER"`
+ SourceFile string `json:"SOURCE_FILE"`
}
func watchDirWriteResponse(filename string, resp *watchDirResponseData) {
@@ -90,12 +93,12 @@ func watchDirWriteResponse(filename string, resp *watchDirResponseData) {
os.Rename(filename, dstname)
}
-func watchDirErrorResponse(filename string, code int, errStr string) {
- watchDirWriteResponse(filename, &watchDirResponseData{code, errStr, 0, 0})
+func watchDirErrorResponse(filename string, code int, errStr, sourceFile string) {
+ watchDirWriteResponse(filename, &watchDirResponseData{code, errStr, 0, 0, sourceFile})
}
func watchDirResponse(filename string, result *rhimport.Result) {
- watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut})
+ watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut, result.SourceFile})
}
func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File) (ctx *rhimport.Context, err error) {
@@ -121,6 +124,7 @@ func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File)
ctx.AutotrimLevel = reqdata.AutotrimLevel
ctx.UseMetaData = reqdata.UseMetaData
ctx.SourceUri = reqdata.SourceUri
+ err = ctx.SourceFilePolicy.FromString(reqdata.SourceFilePolicy)
return
}
@@ -129,22 +133,22 @@ func watchDirHandler(conf *rhimport.Config, db *rddb.DBChan, ctx *rhimport.Conte
var err error
if err = ctx.SanityCheck(); err != nil {
- watchDirErrorResponse(filename, http.StatusBadRequest, err.Error())
+ watchDirErrorResponse(filename, http.StatusBadRequest, err.Error(), "")
return
}
var res *rhimport.Result
if res, err = rhimport.FetchFile(ctx); err != nil {
- watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error())
+ watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error(), "")
return
}
if res.ResponseCode != http.StatusOK {
- watchDirErrorResponse(filename, res.ResponseCode, res.ErrorString)
+ watchDirErrorResponse(filename, res.ResponseCode, res.ErrorString, "")
return
}
if res, err = rhimport.ImportFile(ctx); err != nil {
- watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error())
+ watchDirErrorResponse(filename, http.StatusInternalServerError, err.Error(), res.SourceFile)
return
}
if res.ResponseCode == http.StatusOK {
@@ -199,8 +203,13 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) {
}
func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) {
+ first := true
for {
- time.Sleep(5 * time.Second)
+ if !first {
+ time.Sleep(5 * time.Second)
+ }
+ first = false
+
dir, err := os.Open(dirname)
if err != nil {
rhl.Printf("watch-dir-ctrl: %s", err)
@@ -218,6 +227,7 @@ func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) {
}
}
watchDirRun(dir, conf, db)
+ rhdl.Printf("watchDirRun: returned - restring in 5 sec...")
dir.Close()
}
}