From f33185c2530472b5d891bb60a3dfa353285e25f2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 25 Jul 2017 18:38:59 +0200 Subject: [PATCH 1/3] Make tempdir use settings --- standards/7-temp-directory.md | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/standards/7-temp-directory.md b/standards/7-temp-directory.md index fae40af..253241e 100644 --- a/standards/7-temp-directory.md +++ b/standards/7-temp-directory.md @@ -3,38 +3,39 @@ ## Quick information | Information | | | ----------- | --------------------------------------------------------------- | -| Version | 1.0.0 | +| Version | 2.0.0 | | Type | Path / Directory | | MIME | `application/directory` | -| Location | Temporary Directory is located in `/tmp` | +| Location | Temporary Directory is located in `settings.get("tempdir")` | ### Technical Details -A standard temp directory exists at `/tmp` +A standard temp directory exists at `settings.get("tempdir")` This directory is used for storing files temporarily. The point of this directory is to be able to have a standard place to store "junk" files, where the program doesn't have to worry about accidentally overriding another file created by the user. It is NOT a place to store any files that need to be accurately recalled later on. #### Proper Usage in Supporting Programs -To use it properly, a program can (through normal non-interrupted execution) store files in the `/tmp` directory while +To use it properly, a program can (through normal non-interrupted execution) store files in the `settings.get("tempdir")` directory while it is running, and then should promptly delete the file from this directory as soon as possible. #### Proper Support in Supporting OSes (and other systems) -The `/tmp` folder should be deleted then recreated at the startup of the system. Access to this directory should be open +The `settings.get("tempdir")` folder should be deleted then recreated at the startup of the system. Access to this directory should be open and unprotected. It can however be hidden by the operating system, however, this is at the discretion of the OS creator -(and hopefully a user-modifiable config setting as well). **Ensure that you are only hiding /tmp and not other folders +(and hopefully a user-modifiable config setting as well). **Ensure that you are only hiding `settings.get("tempdir")` and not other folders called tmp** ### Examples #### Usage (In a Program) ```lua -local junkFile = fs.open("/tmp/blah", "w") +local tempdir = settings.get("tempdir") +local junkFile = fs.open(fs.combine(tempdir,"blah"), "w") junkFile.write("So since I can write here, I'm not at risk of messing a user's stuff up.") junkFile.close() -if fs.exists("/tmp/blah") then - local junkFile = fs.open("/tmp/blah", "r") +if fs.exists(fs.combine(tempdir,"blah")) then + local junkFile = fs.open(fs.combine(tempdir,"blah"), "r") -- junkFile could be nil, so you will want to check for that. There is no guarentee the file still exists - the temp -- directory is not persistent. local var = junkFile.readAll() @@ -46,8 +47,14 @@ end ```lua -- This is a startup file. Append this code to the top of your startup file (or close to it) to adhere to the standard. -fs.delete("/tmp") -fs.makeDir("/tmp") +-- check if tempdir setting exists; If it doesn't, set it +if settings.get("tempdir") == nil then + settings.set("tempdir", "/tmp") +end + +local tempdir = settings.get("tempdir") +fs.delete(tempdir) +fs.makeDir(tempdir) -- Additionally, it is permissible to hide the folder from the user. The tmp directory might not need to be seen on every OS depending on your target userbase. PLEASE ENSURE YOU ARE ONLY HIDING "/tmp" AND NOT OTHER FOLDERS CALLED "tmp" From 0d9a7d9e2d95073ad4c1376698079d6d45dfd08f Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 25 Jul 2017 19:15:07 +0200 Subject: [PATCH 2/3] Instead of adding the setting it defaults to /tmp --- standards/7-temp-directory.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/standards/7-temp-directory.md b/standards/7-temp-directory.md index 253241e..6be10d9 100644 --- a/standards/7-temp-directory.md +++ b/standards/7-temp-directory.md @@ -47,12 +47,8 @@ end ```lua -- This is a startup file. Append this code to the top of your startup file (or close to it) to adhere to the standard. --- check if tempdir setting exists; If it doesn't, set it -if settings.get("tempdir") == nil then - settings.set("tempdir", "/tmp") -end - -local tempdir = settings.get("tempdir") +-- Get tempdir, or fall back to "/tmp" +local tempdir = settings.get("/tmp") fs.delete(tempdir) fs.makeDir(tempdir) From 32f9214a7a8ad9055d2766ede303fd1bd9ff9399 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 25 Jul 2017 19:16:25 +0200 Subject: [PATCH 3/3] Fixed some of my brainlag --- standards/7-temp-directory.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standards/7-temp-directory.md b/standards/7-temp-directory.md index 6be10d9..983f925 100644 --- a/standards/7-temp-directory.md +++ b/standards/7-temp-directory.md @@ -48,7 +48,7 @@ end -- This is a startup file. Append this code to the top of your startup file (or close to it) to adhere to the standard. -- Get tempdir, or fall back to "/tmp" -local tempdir = settings.get("/tmp") +local tempdir = settings.get("tempdir", "/tmp") fs.delete(tempdir) fs.makeDir(tempdir)