diff --git a/Scenario.lua b/Scenario.lua index d9c4c6e..8713429 100644 --- a/Scenario.lua +++ b/Scenario.lua @@ -390,8 +390,9 @@ local function sandboxFsCreateFile(a_Table) -- Return the action implementation: return function(a_Simulator) - a_Simulator.logger:trace("Scenario: Creating file %s", a_Table.fileName) - local f = assert(io.open(a_Table.fileName, "wb")) + local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName + a_Simulator.logger:trace("Scenario: Creating file %s", fileName) + local f = assert(io.open(fileName, "wb")) if (a_Table.contents) then f:write(a_Table.contents) end @@ -415,8 +416,10 @@ local function sandboxFsCopyFile(a_Table) -- Return the action implementation: return function(a_Simulator) - a_Simulator.logger:trace("Scenario: Copying file %s to %s", a_Table.srcFileName, a_Table.dstFileName) - assert(utils.copyFile(a_Table.srcFileName, a_Table.dstFileName)) + local srcFileName = a_Simulator.options.scenarioPath .. a_Table.srcFileName + local dstFileName = a_Simulator.options.scenarioPath .. a_Table.dstFileName + a_Simulator.logger:trace("Scenario: Copying file %s to %s", srcFileName, dstFileName) + assert(utils.copyFile(srcFileName, dstFileName)) end end @@ -436,7 +439,9 @@ local function sandboxFsRenameFile(a_Table) -- Return the action implementation: return function(a_Simulator) - a_Simulator.logger:trace("Scenario: Renaming file %s to %s", a_Table.oldFileName, a_Table.newFileName) + local oldFileName = a_Simulator.options.scenarioPath .. a_Table.oldFileName + local newFileName = a_Simulator.options.scenarioPath .. a_Table.newFileName + a_Simulator.logger:trace("Scenario: Renaming file %s to %s", oldFileName, newFileName) assert(os.rename(a_Table.oldFileName, a_Table.newFileName)) end end @@ -454,8 +459,9 @@ local function sandboxFsDeleteFile(a_Table) -- Return the action implementation: return function(a_Simulator) - a_Simulator.logger.trace("Scenario: Deleting file %s", a_Table.fileName) - assert(os.remove(a_Table.fileName)) + local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName + a_Simulator.logger.trace("Scenario: Deleting file %s", fileName) + assert(os.remove(fileName)) end end @@ -472,8 +478,9 @@ local function sandboxFsCreateFolder(a_Table) -- Return the implementation: return function(a_Simulator) - a_Simulator.logger.trace("Scenario: Creating folder %s", a_Table.path) - assert(utils.createFolderRecursive(a_Table.path), string.format("Cannot create folder %s", a_Table.path)) + local path = a_Simulator.options.scenarioPath .. a_Table.path + a_Simulator.logger.trace("Scenario: Creating folder %s", path) + assert(utils.createFolderRecursive(path), string.format("Cannot create folder %s", path)) end end @@ -493,6 +500,8 @@ local function sandboxFsRenameFolder(a_Table) -- Return the implementation: return function(a_Simulator) + local oldPath = a_Simulator.options.scenarioPath .. a_Table.oldPath + local newPath = a_Simulator.options.scenarioPath .. a_Table.newPath a_Simulator.logger:trace("Scenario: Renaming folder %s to %s", a_Table.oldPath, a_Table.newPath) assert(os.rename(a_Table.oldPath, a_Table.newPath)) end @@ -511,9 +520,10 @@ local function sandboxFsDeleteFolder(a_Table) -- Return the action implementation: return function(a_Simulator) - a_Simulator.logger.trace("Scenario: Deleting folder %s", a_Table.path) - assert(utils.deleteFolderContents(a_Table.path)) - assert(os.remove(a_Table.path)) + local path = a_Simulator.options.scenarioPath .. a_Table.path + a_Simulator.logger.trace("Scenario: Deleting folder %s", path) + assert(utils.deleteFolderContents(path)) + assert(os.remove(path)) end end diff --git a/ScenarioFiles.md b/ScenarioFiles.md index 4c43ea6..885f09a 100644 --- a/ScenarioFiles.md +++ b/ScenarioFiles.md @@ -152,22 +152,22 @@ b b b Takes a dictionary table as its parameter. The `choices` specifies an array of strings that are used for the parameters. The 'maxLen' specifies the maximum number of parameters, the optional `minLen` (default: 0) specifies the minimum number of parameters. ## fsCreateFile -Creates a file and, optionally, fills it with data. Takes a dictionary table as its parameter. The `fileName` specifies the file to create. Note that redirection is NOT performed on this filename. The optional `contents` value specifies the contents to write into the new file. +Creates a file and, optionally, fills it with data. Takes a dictionary table as its parameter. The `fileName` specifies the file to create. Note that redirection is NOT performed on this filename. The optional `contents` value specifies the contents to write into the new file. The filename is relative to the folder of the Scenario file. ## fsCopyFile -Copies a file. Takes a dictionary table as its parameter. The `srcFileName` value specifies the file to copy, the `dstFileName` value specifies the destination where to copy the file. Note that the destination folder must exist, this action doesn't create folders. Note that redirection is NOT performed on either of the filenames. +Copies a file. Takes a dictionary table as its parameter. The `srcFileName` value specifies the file to copy, the `dstFileName` value specifies the destination where to copy the file. Note that the destination folder must exist, this action doesn't create folders. Note that redirection is NOT performed on either of the filenames. The filenames are relative to the folder of the Scenario file. ## fsRenameFile -Renames a file. Takes a dictionary table as its parameter. The `oldFileName` value specifies the file to rename, the `newFileName` value specifies the new filename. Note that the path to `newFileName` must exist, fsRenameFile doesn't create folders. Also note that if `oldFileName` specifies a folder, the action will succeed, too (Lua's os.rename() doesn't distinguish between files and folders). Note that redirection is NOT performed on either of the filenames. +Renames a file. Takes a dictionary table as its parameter. The `oldFileName` value specifies the file to rename, the `newFileName` value specifies the new filename. Note that the path to `newFileName` must exist, fsRenameFile doesn't create folders. Also note that if `oldFileName` specifies a folder, the action will succeed, too (Lua's os.rename() doesn't distinguish between files and folders). Note that redirection is NOT performed on either of the filenames. The filenames are relative to the folder of the Scenario file. ## fsDeleteFile -Deletes a file. Takes a dictionary table as its parameter. The `fileName` value specifies the file to delete. Note that if `fileName` specifies an empty folder, the action will succeed, to (Lua's os.remove() doesn't distinguish between files and folders). Note that redirection is NOT performed on the filename. +Deletes a file. Takes a dictionary table as its parameter. The `fileName` value specifies the file to delete. Note that if `fileName` specifies an empty folder, the action will succeed, to (Lua's os.remove() doesn't distinguish between files and folders). Note that redirection is NOT performed on the filename. The filename is relative to the folder of the Scenario file. ## fsCreateFolder -Creates a folder, recursively. Takes a dictionary table as its parameter. The `path` value specifies the folder to create. It works recursively - it creates any parent folders that are needed for the final folder to be created. Performs no action if the folder already exists. Note that redirection is NOT performed on the path. +Creates a folder, recursively. Takes a dictionary table as its parameter. The `path` value specifies the folder to create. It works recursively - it creates any parent folders that are needed for the final folder to be created. Performs no action if the folder already exists. Note that redirection is NOT performed on the path. The path is relative to the folder of the Scenario file. ## fsRenameFolder -Renames a folder. Takes a dictionary table as its parameter. The `oldPath` value specifies the folder to rename, the `newPath` value specifies the new name for the folder. Note that if `oldPath` specifies a file, the action will rename the file successfully (Lua's os.rename() doesn't distinguish between files and folders). Note that redirection is not performed on either of the paths. +Renames a folder. Takes a dictionary table as its parameter. The `oldPath` value specifies the folder to rename, the `newPath` value specifies the new name for the folder. Note that if `oldPath` specifies a file, the action will rename the file successfully (Lua's os.rename() doesn't distinguish between files and folders). Note that redirection is not performed on either of the paths. The paths are relative to the folder of the Scenario file. ## fsDeleteFolder -Deletes a folder, recursively. Takes a dictionary table as its parameter. The `path` value specifies the folder to delete. The action first recursively deletes the contents of the folder, then deletes the folder itself. It may fail if `path` points to a file (depends on LuaFileSystem's handling of lfs.dir() for files). Note that redirection is NOT performed on the path. +Deletes a folder, recursively. Takes a dictionary table as its parameter. The `path` value specifies the folder to delete. The action first recursively deletes the contents of the folder, then deletes the folder itself. It may fail if `path` points to a file (depends on LuaFileSystem's handling of lfs.dir() for files). Note that redirection is NOT performed on the path. The path is relative to the folder of the Scenario file.