summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-12 17:54:24 -0500
committerDavid Robillard <d@drobilla.net>2022-11-16 10:22:55 -0500
commit42439bc6e35eef7c3cc905c60b5924c200b49ec8 (patch)
tree8a924183525ea0197ce26dbc68ab7564ef72b1d9
parenta2d40769d25c9495edce67be67be0ac36491ce80 (diff)
downloadlilv-42439bc6e35eef7c3cc905c60b5924c200b49ec8.tar.gz
lilv-42439bc6e35eef7c3cc905c60b5924c200b49ec8.tar.bz2
lilv-42439bc6e35eef7c3cc905c60b5924c200b49ec8.zip
Use zix_file_lock()
-rw-r--r--src/filesystem.c30
-rw-r--r--src/filesystem.h16
-rw-r--r--src/state.c4
-rw-r--r--test/test_filesystem.c22
4 files changed, 2 insertions, 70 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index 7e42dbd..b17f67a 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -19,10 +19,6 @@
# include <unistd.h>
#endif
-#if USE_FLOCK && USE_FILENO
-# include <sys/file.h>
-#endif
-
#include <sys/stat.h>
#include <stdbool.h>
@@ -210,32 +206,6 @@ lilv_symlink(const char* oldpath, const char* newpath)
return ret;
}
-int
-lilv_flock(FILE* file, bool lock, bool block)
-{
-#ifdef _WIN32
- HANDLE handle = (HANDLE)_get_osfhandle(fileno(file));
- OVERLAPPED overlapped = {0};
-
- if (lock) {
- const DWORD flags =
- (LOCKFILE_EXCLUSIVE_LOCK | (block ? 0 : LOCKFILE_FAIL_IMMEDIATELY));
-
- return !LockFileEx(handle, flags, 0, UINT32_MAX, UINT32_MAX, &overlapped);
- } else {
- return !UnlockFileEx(handle, 0, UINT32_MAX, UINT32_MAX, &overlapped);
- }
-#elif USE_FLOCK && USE_FILENO
- return flock(fileno(file),
- (lock ? LOCK_EX : LOCK_UN) | (block ? 0 : LOCK_NB));
-#else
- (void)file;
- (void)lock;
- (void)block;
- return 0;
-#endif
-}
-
void
lilv_dir_for_each(const char* path,
void* data,
diff --git a/src/filesystem.h b/src/filesystem.h
index 33294da..e50b1af 100644
--- a/src/filesystem.h
+++ b/src/filesystem.h
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: ISC
#include <stdbool.h>
-#include <stdio.h>
/// Return true iff `path` is an absolute path
bool
@@ -55,21 +54,6 @@ int
lilv_symlink(const char* oldpath, const char* newpath);
/**
- Set or remove an advisory exclusive lock on `file`.
-
- If the `lock` is true and the file is already locked by another process, or
- by this process via a different file handle, then this will not succeed and
- non-zero will be returned.
-
- @param file Handle for open file to lock.
- @param lock True to set lock, false to release lock.
- @param block If true, then this call will block until the lock is acquired.
- @return Zero on success.
-*/
-int
-lilv_flock(FILE* file, bool lock, bool block);
-
-/**
Visit every file in the directory at `path`.
@param path A path to a directory.
diff --git a/src/state.c b/src/state.c
index c0c9400..7ee8f87 100644
--- a/src/state.c
+++ b/src/state.c
@@ -990,9 +990,9 @@ add_state_to_manifest(LilvWorld* lworld,
}
SerdWriter* writer = ttl_file_writer(wfd, &manifest, &env);
- lilv_flock(wfd, true, true);
+ zix_file_lock(wfd, ZIX_FILE_LOCK_BLOCK);
sord_write(model, writer, NULL);
- lilv_flock(wfd, false, true);
+ zix_file_unlock(wfd, ZIX_FILE_LOCK_BLOCK);
serd_writer_free(writer);
fclose(wfd);
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 021d66f..75db963 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -155,27 +155,6 @@ test_is_directory(void)
free(temp_dir);
}
-static void
-test_flock(void)
-{
- char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
-
- FILE* const f1 = fopen(file_path, "w");
- FILE* const f2 = fopen(file_path, "w");
-
- assert(!lilv_flock(f1, true, false));
- assert(lilv_flock(f2, true, false));
- assert(!lilv_flock(f1, false, false));
-
- fclose(f2);
- fclose(f1);
- assert(!zix_remove(file_path));
- assert(!zix_remove(temp_dir));
- free(file_path);
- free(temp_dir);
-}
-
typedef struct {
size_t n_names;
char** names;
@@ -238,7 +217,6 @@ main(void)
test_path_parent();
test_path_filename();
test_is_directory();
- test_flock();
test_dir_for_each();
return 0;