Merge pull request #27863 from DaanDeMeyer/copy-lock
Add helpers to lock a directory before copying into it
This commit is contained in:
+1
-1
@@ -1177,7 +1177,7 @@ int xopenat_lock(
|
||||
|
||||
/* POSIX/UNPOSIX locks don't work on directories (errno is set to -EBADF so let's return early with
|
||||
* the same error here). */
|
||||
if (FLAGS_SET(open_flags, O_DIRECTORY) && locktype != LOCK_BSD)
|
||||
if (FLAGS_SET(open_flags, O_DIRECTORY) && !IN_SET(locktype, LOCK_BSD, LOCK_NONE))
|
||||
return -EBADF;
|
||||
|
||||
for (;;) {
|
||||
|
||||
@@ -174,6 +174,8 @@ int lock_generic(int fd, LockType type, int operation) {
|
||||
assert(fd >= 0);
|
||||
|
||||
switch (type) {
|
||||
case LOCK_NONE:
|
||||
return 0;
|
||||
case LOCK_BSD:
|
||||
return RET_NERRNO(flock(fd, operation));
|
||||
case LOCK_POSIX:
|
||||
|
||||
@@ -34,6 +34,7 @@ void unposix_unlockpp(int **fd);
|
||||
_cleanup_(unposix_unlockpp) _unused_ int *CONCATENATE(_cleanup_unposix_unlock_, UNIQ) = &(fd)
|
||||
|
||||
typedef enum LockType {
|
||||
LOCK_NONE, /* Don't lock the file descriptor. Useful if you need to conditionally lock a file. */
|
||||
LOCK_BSD,
|
||||
LOCK_POSIX,
|
||||
LOCK_UNPOSIX,
|
||||
|
||||
Reference in New Issue
Block a user