diff options
author | jwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68> | 2001-10-01 19:12:49 +0000 |
---|---|---|
committer | jwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68> | 2001-10-01 19:12:49 +0000 |
commit | af9062afa03e155bac86b2ade1127bab861e48a8 (patch) | |
tree | c47bfb441a9549a7fc28e65ed415bbb80a82a85d | |
parent | 00faf6a4281257b20ae54bbc99d79b08f8672178 (diff) | |
download | libapr-af9062afa03e155bac86b2ade1127bab861e48a8.tar.gz |
Even though it's not unusual for temporary files to be unlinked as soon as
they're open on Unix, it makes the use of those files harder in some cases.
For example, the filename we were getting back from apr_file_mktemp() was
useless because the file had already been unlinked. Now we defer the unlink
until the file is actually closed. This also makes the behavior on Unix
somewhat more consistent with other platforms.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62390 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | file_io/unix/mktemp.c | 1 | ||||
-rw-r--r-- | file_io/unix/open.c | 6 |
3 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,10 @@ Changes with APR b1 + *) Files opened on Unix with the flag APR_DELONCLOSE are now + not unlinked until they are actually closed, rather than as + soon as they're opened. The old approach worked but made + handling temp files harder. [Cliff Woolley] + *) Fix potential segfault when closing a file on Unix. If apr_file_close() was called and it failed, it would not deregister the file cleanup. Therefore the cleanup would diff --git a/file_io/unix/mktemp.c b/file_io/unix/mktemp.c index fac3cb4b6..447d97965 100644 --- a/file_io/unix/mktemp.c +++ b/file_io/unix/mktemp.c @@ -196,7 +196,6 @@ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_p (*fp)->filedes = fd; #endif - apr_file_remove((*fp)->fname, p); #ifdef WIN32 apr_pool_cleanup_register((*fp)->cntxt, (void *)(*fp), file_cleanup, file_cleanup); diff --git a/file_io/unix/open.c b/file_io/unix/open.c index 1ecb363f0..f61e2bf47 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -69,6 +69,9 @@ apr_status_t apr_unix_file_cleanup(void *thefile) rc = close(file->filedes); if (rc == 0) { file->filedes = -1; + if (file->flags & APR_DELONCLOSE) { + unlink(file->fname); + } #if APR_HAS_THREADS if (file->thlock) { rv = apr_lock_destroy(file->thlock); @@ -156,9 +159,6 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr return errno; } - if (flag & APR_DELONCLOSE) { - unlink(fname); - } (*new)->pipe = 0; (*new)->timeout = -1; (*new)->ungetchar = -1; |