On 10/14/2010 04:32 PM, Denys Vlasenko wrote:
Jiri found a bug in previous patch, so here goes v.2
Before this patch, dd_opendir(".") was creating
lock file "..lock", which is obviously wrong.
This patch makes dd_opendir use realpath(dir).
This makes dd_opendir(".") and similar cases correctly
determine what's its parent directory and therefore
use correct lock file name.
dd_create can't use realpath, since it will always return NULL
on not-yet existing directory. But this is not a problem, since
dd_create(".") isn't a sane operation. So we continue to use
old code. I only added a sanity check to refuse names ending
in . and .. - just in case.
Run-tested.
Please review.
-static char* rm_trailing_slashes(const char *dir)
-{
- unsigned len = strlen(dir);
- while (len != 0 && dir[len-1] == '/')
- len--;
- return xstrndup(dir, len);
-}
static bool exist_file_dir(const char *path)
{
struct stat buf;
@@ -171,12 +159,27 @@ void dd_close(struct dump_dir *dd)
free(dd);
}
-+static char* rm_trailing_slashes(const char *dir)
+{
+ unsigned len = strlen(dir);
+ while (len != 0 && dir[len-1] == '/')
+ len--;
+ return xstrndup(dir, len);
+}
+
How is it related to ' fix dump dir locking with directories named ., ..'?
If you need to move it, please do it as an another commit.
--
Nikola