[ovs-dev] [PATCH] lib/lockfile.c: Fix the name of the lockfile on Windows

Nithin Raju nithin at vmware.com
Thu Jul 24 18:46:07 UTC 2014


On Windows, for a filename such as ..\conf.db, the name of the lockfile
constructed by lockfile_name() turns out to be ...\conf.db.~lock~. This is
not a valid path.  The extra '.' added to make the file hidden does not work
as expected if backslash ('\') is used for directory separation.

A simple fix is to not use '.' on Windows to hide the file.

Signed-off-by: Nithin Raju <nithin at vmware.com>
---
 lib/lockfile.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/lockfile.c b/lib/lockfile.c
index 1ef6251..6862509 100644
--- a/lib/lockfile.c
+++ b/lib/lockfile.c
@@ -74,6 +74,11 @@ lockfile_name(const char *filename_)
     char *filename;
     const char *slash;
     char *lockname;
+#ifndef _WIN32
+    char hidden_prefix[] = ".";
+#else
+    char hidden_prefix[] = "";
+#endif
 
     /* If 'filename_' is a symlink, base the name of the lockfile on the
      * symlink's target rather than the name of the symlink.  That way, if a
@@ -83,9 +88,10 @@ lockfile_name(const char *filename_)
     filename = follow_symlinks(filename_);
     slash = strrchr(filename, '/');
     lockname = (slash
-                ? xasprintf("%.*s/.%s.~lock~",
-                            (int) (slash - filename), filename, slash + 1)
-                : xasprintf(".%s.~lock~", filename));
+                ? xasprintf("%.*s/%s%s.~lock~",
+                            (int) (slash - filename), filename, hidden_prefix,
+                            slash + 1)
+                : xasprintf("%s%s.~lock~", hidden_prefix, filename));
     free(filename);
 
     return lockname;
-- 
1.9.1




More information about the dev mailing list