[Bf-blender-cvs] [45ed398b77f] tmp-flock: BLI_fileops flock: fixes.

Bastien Montagne noreply at git.blender.org
Tue Jan 17 17:05:49 CET 2023


Commit: 45ed398b77f341f872d04e5ce297dd65aeec7711
Author: Bastien Montagne
Date:   Tue Jan 17 17:05:26 2023 +0100
Branches: tmp-flock
https://developer.blender.org/rB45ed398b77f341f872d04e5ce297dd65aeec7711

BLI_fileops flock: fixes.

===================================================================

M	source/blender/blenlib/intern/fileops.c
M	source/blender/blenlib/tests/BLI_fileops_test.cc

===================================================================

diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 4a37061d936..40dfd1b656b 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -961,15 +961,15 @@ int BLI_access(const char *filepath, int mode)
 
 bool BLI_flock_shared(const int file_descriptor, const bool is_blocking)
 {
-  return flock(file_descriptor, LOCK_SH | (is_blocking ? 0 : LOCK_NB));
+  return !flock(file_descriptor, LOCK_SH | (is_blocking ? 0 : LOCK_NB));
 }
 bool BLI_flock_exclusive(const int file_descriptor, const bool is_blocking)
 {
-  return flock(file_descriptor, LOCK_EX | (is_blocking ? 0 : LOCK_NB));
+  return !flock(file_descriptor, LOCK_EX | (is_blocking ? 0 : LOCK_NB));
 }
 bool BLI_flock_release(const int file_descriptor)
 {
-  return flock(file_descriptor, LOCK_UN);
+  return !flock(file_descriptor, LOCK_UN);
 }
 
 int BLI_delete(const char *file, bool dir, bool recursive)
diff --git a/source/blender/blenlib/tests/BLI_fileops_test.cc b/source/blender/blenlib/tests/BLI_fileops_test.cc
index 67e4c640358..568fff5a52b 100644
--- a/source/blender/blenlib/tests/BLI_fileops_test.cc
+++ b/source/blender/blenlib/tests/BLI_fileops_test.cc
@@ -90,6 +90,8 @@ TEST(fileops, flock_file)
   ASSERT_FALSE(flock_result);
   flock_result = BLI_flock_shared(fhandle_2, false);
   ASSERT_FALSE(flock_result);
+  flock_result = BLI_flock_shared(-1, false);
+  ASSERT_FALSE(flock_result);
 }
 
 }  // namespace blender::tests



More information about the Bf-blender-cvs mailing list