Skip to content

Commit ca03c9c

Browse files
committed
FS operations in Scenario file are now relative to the Scenario file.
1 parent 6461d38 commit ca03c9c

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
@@ -380,8 +380,9 @@ local function sandboxFsCreateFile(a_Table)
380380

381381
-- Return the action implementation:
382382
return function(a_Simulator)
383-
a_Simulator.logger:trace("Scenario: Creating file %s", a_Table.fileName)
384-
local f = assert(io.open(a_Table.fileName, "wb"))
383+
local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName
384+
a_Simulator.logger:trace("Scenario: Creating file %s", fileName)
385+
local f = assert(io.open(fileName, "wb"))
385386
if (a_Table.contents) then
386387
f:write(a_Table.contents)
387388
end
@@ -405,8 +406,10 @@ local function sandboxFsCopyFile(a_Table)
405406

406407
-- Return the action implementation:
407408
return function(a_Simulator)
408-
a_Simulator.logger:trace("Scenario: Copying file %s to %s", a_Table.srcFileName, a_Table.dstFileName)
409-
assert(utils.copyFile(a_Table.srcFileName, a_Table.dstFileName))
409+
local srcFileName = a_Simulator.options.scenarioPath .. a_Table.srcFileName
410+
local dstFileName = a_Simulator.options.scenarioPath .. a_Table.dstFileName
411+
a_Simulator.logger:trace("Scenario: Copying file %s to %s", srcFileName, dstFileName)
412+
assert(utils.copyFile(srcFileName, dstFileName))
410413
end
411414
end
412415

@@ -426,7 +429,9 @@ local function sandboxFsRenameFile(a_Table)
426429

427430
-- Return the action implementation:
428431
return function(a_Simulator)
429-
a_Simulator.logger:trace("Scenario: Renaming file %s to %s", a_Table.oldFileName, a_Table.newFileName)
432+
local oldFileName = a_Simulator.options.scenarioPath .. a_Table.oldFileName
433+
local newFileName = a_Simulator.options.scenarioPath .. a_Table.newFileName
434+
a_Simulator.logger:trace("Scenario: Renaming file %s to %s", oldFileName, newFileName)
430435
assert(os.rename(a_Table.oldFileName, a_Table.newFileName))
431436
end
432437
end
@@ -444,8 +449,9 @@ local function sandboxFsDeleteFile(a_Table)
444449

445450
-- Return the action implementation:
446451
return function(a_Simulator)
447-
a_Simulator.logger.trace("Scenario: Deleting file %s", a_Table.fileName)
448-
assert(os.remove(a_Table.fileName))
452+
local fileName = a_Simulator.options.scenarioPath .. a_Table.fileName
453+
a_Simulator.logger.trace("Scenario: Deleting file %s", fileName)
454+
assert(os.remove(fileName))
449455
end
450456
end
451457

@@ -462,8 +468,9 @@ local function sandboxFsCreateFolder(a_Table)
462468

463469
-- Return the implementation:
464470
return function(a_Simulator)
465-
a_Simulator.logger.trace("Scenario: Creating folder %s", a_Table.path)
466-
assert(utils.createFolderRecursive(a_Table.path), string.format("Cannot create folder %s", a_Table.path))
471+
local path = a_Simulator.options.scenarioPath .. a_Table.path
472+
a_Simulator.logger.trace("Scenario: Creating folder %s", path)
473+
assert(utils.createFolderRecursive(path), string.format("Cannot create folder %s", path))
467474
end
468475
end
469476

@@ -483,6 +490,8 @@ local function sandboxFsRenameFolder(a_Table)
483490

484491
-- Return the implementation:
485492
return function(a_Simulator)
493+
local oldPath = a_Simulator.options.scenarioPath .. a_Table.oldPath
494+
local newPath = a_Simulator.options.scenarioPath .. a_Table.newPath
486495
a_Simulator.logger:trace("Scenario: Renaming folder %s to %s", a_Table.oldPath, a_Table.newPath)
487496
assert(os.rename(a_Table.oldPath, a_Table.newPath))
488497
end
@@ -501,9 +510,10 @@ local function sandboxFsDeleteFolder(a_Table)
501510

502511
-- Return the action implementation:
503512
return function(a_Simulator)
504-
a_Simulator.logger.trace("Scenario: Deleting folder %s", a_Table.path)
505-
assert(utils.deleteFolderContents(a_Table.path))
506-
assert(os.remove(a_Table.path))
513+
local path = a_Simulator.options.scenarioPath .. a_Table.path
514+
a_Simulator.logger.trace("Scenario: Deleting folder %s", path)
515+
assert(utils.deleteFolderContents(path))
516+
assert(os.remove(path))
507517
end
508518
end
509519

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)