* [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set
@ 2020-03-03 23:01 Vladislav Shpilevoy
2020-03-04 13:59 ` Nikita Pettik
2020-03-05 7:35 ` Kirill Yukhin
0 siblings, 2 replies; 3+ messages in thread
From: Vladislav Shpilevoy @ 2020-03-03 23:01 UTC (permalink / raw)
To: tarantool-patches, imun, korablev
TMPDIR is an environment variable used to tell what a directory
should be used to create temporary files. It is described in the
POSIX standard, and should be used by programs creating temporary
files.
Closes #4794
@TarantoolBot document
Title: fio.tempdir() $TMPDIR
fio.tempdir() stores created temporary directory into /tmp by
default. This can be changed by setting TMPDIR environment
variable. Before starting Tarantool, or at runtime by
os.setenv().
---
Branch: http://github.com/tarantool/tarantool/tree/gerold103/gh-4794-tmpdir
Issue: https://github.com/tarantool/tarantool/issues/4794
@ChangeLog
- fio.tempdir() uses TMPDIR as a path to a place where to create
temporary directories (gh-4794).
Changes in V2:
- Dropped commit about custom template instead of XXXXXX.
src/lib/core/coio_file.c | 11 ++++---
test/app/fio.result | 68 ++++++++++++++++++++++++++++++++++++++++
test/app/fio.test.lua | 28 +++++++++++++++++
3 files changed, 103 insertions(+), 4 deletions(-)
diff --git a/src/lib/core/coio_file.c b/src/lib/core/coio_file.c
index 62388344e..e2345567c 100644
--- a/src/lib/core/coio_file.c
+++ b/src/lib/core/coio_file.c
@@ -466,13 +466,16 @@ coio_tempdir(char *path, size_t path_len)
{
INIT_COEIO_FILE(eio);
- if (path_len < sizeof("/tmp/XXXXXX") + 1) {
+ const char *tmpdir = getenv("TMPDIR");
+ if (tmpdir == NULL)
+ tmpdir = "/tmp";
+ int rc = snprintf(path, path_len, "%s/XXXXXX", tmpdir);
+ if (rc < 0)
+ return -1;
+ if ((size_t) rc >= path_len) {
errno = ENOMEM;
return -1;
}
-
- snprintf(path, path_len, "/tmp/XXXXXX");
-
eio.tempdir.tpl = path;
eio_req *req =
eio_custom(coio_do_tempdir, 0, coio_complete, &eio);
diff --git a/test/app/fio.result b/test/app/fio.result
index f83c43f44..cd18ed32c 100644
--- a/test/app/fio.result
+++ b/test/app/fio.result
@@ -1456,3 +1456,71 @@ fio.mktree('/dev/null/dir')
- false
- 'Error creating directory /dev/null: File exists'
...
+--
+-- gh-4794: fio.tempdir() should use $TMPDIR.
+--
+cwd = fio.cwd()
+---
+...
+old_tmpdir = os.getenv('TMPDIR')
+---
+...
+tmpdir = cwd..'/tmp'
+---
+...
+fio.mkdir(tmpdir)
+---
+- true
+...
+os.setenv('TMPDIR', tmpdir)
+---
+...
+dir = fio.tempdir()
+---
+...
+dir:find(tmpdir) ~= nil or {dir, tmpdir}
+---
+- true
+...
+fio.stat(dir) ~= nil or fio.stat(dir)
+---
+- true
+...
+tmpdir = cwd..'/tmp2'
+---
+...
+os.setenv('TMPDIR', tmpdir)
+---
+...
+fio.tempdir()
+---
+- null
+- 'fio: No such file or directory'
+...
+os.setenv('TMPDIR', nil)
+---
+...
+dir = fio.tempdir()
+---
+...
+dir:find('/tmp') ~= nil or dir
+---
+- true
+...
+tmpdir = cwd..'/'..string.rep('t', 5000)
+---
+...
+os.setenv('TMPDIR', tmpdir)
+---
+...
+fio.tempdir()
+---
+- null
+- 'fio: Cannot allocate memory'
+...
+tmpdir = nil
+---
+...
+os.setenv('TMPDIR', old_tmpdir)
+---
+...
diff --git a/test/app/fio.test.lua b/test/app/fio.test.lua
index 56c957d8a..242ff08ad 100644
--- a/test/app/fio.test.lua
+++ b/test/app/fio.test.lua
@@ -474,3 +474,31 @@ test_run:cmd("clear filter")
--
fio.mktree('/dev/null')
fio.mktree('/dev/null/dir')
+
+--
+-- gh-4794: fio.tempdir() should use $TMPDIR.
+--
+cwd = fio.cwd()
+old_tmpdir = os.getenv('TMPDIR')
+
+tmpdir = cwd..'/tmp'
+fio.mkdir(tmpdir)
+os.setenv('TMPDIR', tmpdir)
+dir = fio.tempdir()
+dir:find(tmpdir) ~= nil or {dir, tmpdir}
+fio.stat(dir) ~= nil or fio.stat(dir)
+
+tmpdir = cwd..'/tmp2'
+os.setenv('TMPDIR', tmpdir)
+fio.tempdir()
+
+os.setenv('TMPDIR', nil)
+dir = fio.tempdir()
+dir:find('/tmp') ~= nil or dir
+
+tmpdir = cwd..'/'..string.rep('t', 5000)
+os.setenv('TMPDIR', tmpdir)
+fio.tempdir()
+tmpdir = nil
+
+os.setenv('TMPDIR', old_tmpdir)
--
2.21.1 (Apple Git-122.3)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set
2020-03-03 23:01 [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set Vladislav Shpilevoy
@ 2020-03-04 13:59 ` Nikita Pettik
2020-03-05 7:35 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: Nikita Pettik @ 2020-03-04 13:59 UTC (permalink / raw)
To: Vladislav Shpilevoy; +Cc: tarantool-patches
On 04 Mar 00:01, Vladislav Shpilevoy wrote:
> TMPDIR is an environment variable used to tell what a directory
> should be used to create temporary files. It is described in the
> POSIX standard, and should be used by programs creating temporary
> files.
>
> Closes #4794
>
> @TarantoolBot document
> Title: fio.tempdir() $TMPDIR
>
> fio.tempdir() stores created temporary directory into /tmp by
> default. This can be changed by setting TMPDIR environment
> variable. Before starting Tarantool, or at runtime by
> os.setenv().
> ---
LGTM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set
2020-03-03 23:01 [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set Vladislav Shpilevoy
2020-03-04 13:59 ` Nikita Pettik
@ 2020-03-05 7:35 ` Kirill Yukhin
1 sibling, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2020-03-05 7:35 UTC (permalink / raw)
To: Vladislav Shpilevoy; +Cc: tarantool-patches
Hello,
On 04 мар 00:01, Vladislav Shpilevoy wrote:
> TMPDIR is an environment variable used to tell what a directory
> should be used to create temporary files. It is described in the
> POSIX standard, and should be used by programs creating temporary
> files.
>
> Closes #4794
LGTM.
I've checked the patch into master.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-05 7:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 23:01 [Tarantool-patches] [PATCH v2 1/1] fio: respect $TMPDIR in fio.tempdir(), when it is set Vladislav Shpilevoy
2020-03-04 13:59 ` Nikita Pettik
2020-03-05 7:35 ` Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox