Skip to content

Commit c33f4a0

Browse files
madmaxoftmathiascode
authored andcommitted
FS operations in Scenario file are now relative to the Scenario file.
1 parent e539aaa commit c33f4a0

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

Scenario.lua

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ local function sandboxFsCreateFile(a_Table)
390390

391391
-- Return the action implementation:
392392
return function(a_Simulator)
393-
a_Simulator.logger:trace("Scenario: Creating file %s", a_Table.fileName)
394-
local f = assert(io.open(a_Table.fileName, "wb"))
393+
local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName
394+
a_Simulator.logger:trace("Scenario: Creating file %s", fileName)
395+
local f = assert(io.open(fileName, "wb"))
395396
if (a_Table.contents) then
396397
f:write(a_Table.contents)
397398
end
@@ -415,8 +416,10 @@ local function sandboxFsCopyFile(a_Table)
415416

416417
-- Return the action implementation:
417418
return function(a_Simulator)
418-
a_Simulator.logger:trace("Scenario: Copying file %s to %s", a_Table.srcFileName, a_Table.dstFileName)
419-
assert(utils.copyFile(a_Table.srcFileName, a_Table.dstFileName))
419+
local srcFileName = a_Simulator.options.scenarioPath .. a_Table.srcFileName
420+
local dstFileName = a_Simulator.options.scenarioPath .. a_Table.dstFileName
421+
a_Simulator.logger:trace("Scenario: Copying file %s to %s", srcFileName, dstFileName)
422+
assert(utils.copyFile(srcFileName, dstFileName))
420423
end
421424
end
422425

@@ -436,7 +439,9 @@ local function sandboxFsRenameFile(a_Table)
436439

437440
-- Return the action implementation:
438441
return function(a_Simulator)
439-
a_Simulator.logger:trace("Scenario: Renaming file %s to %s", a_Table.oldFileName, a_Table.newFileName)
442+
local oldFileName = a_Simulator.options.scenarioPath .. a_Table.oldFileName
443+
local newFileName = a_Simulator.options.scenarioPath .. a_Table.newFileName
444+
a_Simulator.logger:trace("Scenario: Renaming file %s to %s", oldFileName, newFileName)
440445
assert(os.rename(a_Table.oldFileName, a_Table.newFileName))
441446
end
442447
end
@@ -454,8 +459,9 @@ local function sandboxFsDeleteFile(a_Table)
454459

455460
-- Return the action implementation:
456461
return function(a_Simulator)
457-
a_Simulator.logger.trace("Scenario: Deleting file %s", a_Table.fileName)
458-
assert(os.remove(a_Table.fileName))
462+
local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName
463+
a_Simulator.logger.trace("Scenario: Deleting file %s", fileName)
464+
assert(os.remove(fileName))
459465
end
460466
end
461467

@@ -472,8 +478,9 @@ local function sandboxFsCreateFolder(a_Table)
472478

473479
-- Return the implementation:
474480
return function(a_Simulator)
475-
a_Simulator.logger.trace("Scenario: Creating folder %s", a_Table.path)
476-
assert(utils.createFolderRecursive(a_Table.path), string.format("Cannot create folder %s", a_Table.path))
481+
local path = a_Simulator.options.scenarioPath .. a_Table.path
482+
a_Simulator.logger.trace("Scenario: Creating folder %s", path)
483+
assert(utils.createFolderRecursive(path), string.format("Cannot create folder %s", path))
477484
end
478485
end
479486

@@ -493,6 +500,8 @@ local function sandboxFsRenameFolder(a_Table)
493500

494501
-- Return the implementation:
495502
return function(a_Simulator)
503+
local oldPath = a_Simulator.options.scenarioPath .. a_Table.oldPath
504+
local newPath = a_Simulator.options.scenarioPath .. a_Table.newPath
496505
a_Simulator.logger:trace("Scenario: Renaming folder %s to %s", a_Table.oldPath, a_Table.newPath)
497506
assert(os.rename(a_Table.oldPath, a_Table.newPath))
498507
end
@@ -511,9 +520,10 @@ local function sandboxFsDeleteFolder(a_Table)
511520

512521
-- Return the action implementation:
513522
return function(a_Simulator)
514-
a_Simulator.logger.trace("Scenario: Deleting folder %s", a_Table.path)
515-
assert(utils.deleteFolderContents(a_Table.path))
516-
assert(os.remove(a_Table.path))
523+
local path = a_Simulator.options.scenarioPath .. a_Table.path
524+
a_Simulator.logger.trace("Scenario: Deleting folder %s", path)
525+
assert(utils.deleteFolderContents(path))
526+
assert(os.remove(path))
517527
end
518528
end
519529

ScenarioFiles.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,22 @@ b b b
152152
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.
153153

154154
## fsCreateFile
155-
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.
155+
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.
156156

157157
## fsCopyFile
158-
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.
158+
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.
159159

160160
## fsRenameFile
161-
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.
161+
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.
162162

163163
## fsDeleteFile
164-
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.
164+
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.
165165

166166
## fsCreateFolder
167-
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.
167+
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.
168168

169169
## fsRenameFolder
170-
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.
170+
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.
171171

172172
## fsDeleteFolder
173-
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.
173+
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.

0 commit comments

Comments
 (0)