[ovs-dev] [PATCH] Add support for windows filetypes
Alin Serdean
aserdean at cloudbasesolutions.com
Tue Mar 31 16:43:07 UTC 2015
Currently paths that have only forward slashes like the following
"C:/package/binaries/conf.db" work seamlessly.
If we try the native windows filepaths i.e. "C:\package\binaries\conf.db" we
will hit the following problem:
2015-03-31T15:54:17Z|00001|lockfile|WARN|.c:\package\binaries\conf.db.~lock~:
failed to open lock file: Invalid argument
2015-03-31T15:54:17Z|00002|lockfile|WARN|.c:\package\binaries\conf.db.~lock~:
failed to lock file: Invalid argument
ovsdb-server: I/O error: c:\package\binaries\conf.db: failed to lock lockfile
(Invalid argument)
In this patch we update the lockfile_name function to also look for
backslashes, and also accommodate if we have a mix of backslashes and forward
slashes.
Signed-off-by: Alin Gabriel Serdean <aserdean at cloudbasesolutions.com>
---
lib/lockfile.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lib/lockfile.c b/lib/lockfile.c
index 26aee33..4bd556d 100644
--- a/lib/lockfile.c
+++ b/lib/lockfile.c
@@ -74,6 +74,9 @@ lockfile_name(const char *filename_)
char *filename;
const char *slash;
char *lockname;
+#ifdef _WIN32
+ char *backslash;
+#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
@@ -82,6 +85,16 @@ lockfile_name(const char *filename_)
* symlink, not one for each. */
filename = follow_symlinks(filename_);
slash = strrchr(filename, '/');
+
+#ifdef _WIN32
+ /* On Windows look for backslash also. Choose the last position between the
+ * forward slash and backslash. */
+ backslash = strrchr(filename, '\\');
+ if ((slash - filename) < (backslash - filename)) {
+ slash = backslash;
+ }
+#endif
+
lockname = (slash
? xasprintf("%.*s/.%s.~lock~",
(int) (slash - filename), filename, slash + 1)
--
1.9.5.msysgit.0
More information about the dev
mailing list