Skip to content

Commit

Permalink
lockfile: Support \-delimited file names in lockfile_name().
Browse files Browse the repository at this point in the history
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 <[email protected]>
[[email protected] simplified the code]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Alin Serdean authored and blp committed Mar 31, 2015
1 parent 5617ae6 commit d314fc8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ lockfile_name(const char *filename_)
* symlink, not one for each. */
filename = follow_symlinks(filename_);
slash = strrchr(filename, '/');

#ifdef _WIN32
char *backslash = strrchr(filename, '\\');
if (backslash && (!slash || backslash > slash)) {
slash = backslash;
}
#endif

lockname = (slash
? xasprintf("%.*s/.%s.~lock~",
(int) (slash - filename), filename, slash + 1)
Expand Down

0 comments on commit d314fc8

Please sign in to comment.