diff options
Diffstat (limited to 'src/rhimportd')
-rw-r--r-- | src/rhimportd/ctrlTelnet.go | 14 | ||||
-rw-r--r-- | src/rhimportd/ctrlWatchDir.go | 26 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/rhimportd/ctrlTelnet.go b/src/rhimportd/ctrlTelnet.go index 6e859e4..4cbb412 100644 --- a/src/rhimportd/ctrlTelnet.go +++ b/src/rhimportd/ctrlTelnet.go @@ -58,6 +58,7 @@ func telnetHelp(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb. c.Sayln(" UserName string username to use for rdxport interface") c.Sayln(" Password string password to use for rdxport interface") c.Sayln(" SourceUri string uri to the file to import") + c.Sayln(" SourceFilePolicy enum values: auto | keep | delete | delete-with-dir") c.Sayln(" ShowId uint the RHRD show id to import to") c.Sayln(" ClearShowCarts bool clear all show-carts before importing?") c.Sayln(" GroupName string name of music-pool group to import to") @@ -146,6 +147,12 @@ func telnetSetBool(c *telgo.Client, param *bool, val string) { } } +func telnetSetFilePolicy(c *telgo.Client, param *rhimport.FilePolicy, val string) { + if err := param.FromString(val); err != nil { + c.Sayln("invalid value (%s)", err) + } +} + func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool { if len(args) != 3 { c.Sayln("wrong number of arguments") @@ -167,6 +174,8 @@ func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.D ctx.Password = args[2] case "sourceuri": ctx.SourceUri = args[2] + case "sourcefilepolicy": + telnetSetFilePolicy(c, &ctx.SourceFilePolicy, args[2]) case "showid": telnetSetUint(c, &ctx.ShowId, args[2]) case "clearshowcarts": @@ -214,6 +223,7 @@ func telnetShow(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb. c.Sayln(" UserName: %q", ctx.UserName) c.Sayln(" Password: %q", ctx.Password) c.Sayln(" SourceUri: %q", ctx.SourceUri) + c.Sayln(" SourceFilePolicy: %s", ctx.SourceFilePolicy.String()) c.Sayln(" ShowId: %v", ctx.ShowId) c.Sayln(" ClearShowCarts: %v", ctx.ClearShowCarts) c.Sayln(" GroupName: %q", ctx.GroupName) @@ -268,9 +278,9 @@ func telnetRun(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.D } else { c.Sayln("") if res.ResponseCode == http.StatusOK { - c.Sayln("File got succesfully imported into Cart/Cut %d/%d", res.Cart, res.Cut) + c.Sayln("File got succesfully imported into Cart/Cut %d/%d, Source: '%s'", res.Cart, res.Cut, res.SourceFile) } else { - c.Sayln("Fileimport has failed (Cart/Cut %d/%d): %s", res.Cart, res.Cut, res.ErrorString) + c.Sayln("Fileimport has failed (Cart/Cut %d/%d, Source: '%s'): %s", res.Cart, res.Cut, res.SourceFile, res.ErrorString) } } return false 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() } } |