From 433541fcc19731c8b53097a3f71162ae5e94bfc3 Mon Sep 17 00:00:00 2001 From: postmannen Date: Wed, 22 Jun 2022 11:03:59 +0200 Subject: [PATCH] REQToFile now honor the directory path specified --- README.md | 4 ++++ requests.go | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 51c5364..43c0bed 100644 --- a/README.md +++ b/README.md @@ -665,6 +665,8 @@ If used as a **replyMethod** set the **replyMethodArgs** `"replyMethodArgs": ["s Append the output of the reply message to a log file specified with the `directory` and `fileName` fields. +If the value of the **directory** field is not prefixed with `./` or `/` the directory structure file will be created within the **steward data folder** specified in the config file. + ```json [ { @@ -682,6 +684,8 @@ Append the output of the reply message to a log file specified with the `directo Write the output of the reply message to a file specified with the `directory` and `fileName` fields, where the writing will write over any existing content of that file. +If the value of the **directory** field is not prefixed with `./` or `/` the directory structure file will be created within the **steward data folder** specified in the config file. + ```json [ { diff --git a/requests.go b/requests.go index a67871f..dbebe1c 100644 --- a/requests.go +++ b/requests.go @@ -488,20 +488,37 @@ func newReplyMessage(proc process, message Message, outData []byte) { // to create. func selectFileNaming(message Message, proc process) (string, string) { var fileName string - var folderTree string + // As default we set the folder tree to what is specified in the + // message.Directory field. If we don't want that in the checks + // done later we then replace the value with what we want. + folderTree := message.Directory + + checkPrefix := func(s string) bool { + if strings.HasPrefix(s, "./") || strings.HasPrefix(s, "/") { + return true + } + + return false + } switch { case message.PreviousMessage == nil: // If this was a direct request there are no previous message to take // information from, so we use the one that are in the current mesage. fileName = message.FileName - folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode)) + if !checkPrefix(message.Directory) { + folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode)) + } case message.PreviousMessage.ToNode != "": fileName = message.PreviousMessage.FileName - folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode)) + if !checkPrefix(message.PreviousMessage.Directory) { + folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode)) + } case message.PreviousMessage.ToNode == "": fileName = message.PreviousMessage.FileName - folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode)) + if !checkPrefix(message.PreviousMessage.Directory) { + folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode)) + } } return fileName, folderTree