When I use boost file_lock to try to lock files it doesn't own with lock() or lock_sharable(), it throws an exception. Is there any way for it to lock a file owned by a different user so it can modify it safely (the modifying user has correct write permissions).
Asked
Active
Viewed 1,523 times
0
-
file_lock is not used for locking files. It is meant as a cross-process mutex that uses a file to enforce the locking. It is a lock implemented using a file, and has NOTHING to do with actually locking the file for access. – Joe Aug 01 '11 at 18:29
-
yes, i understand what a file lock is in this context. my problem is simply that i cannot lock a file i do not own and would like to know if there are any possible workarounds. – user788171 Aug 01 '11 at 20:21
1 Answers
0
The fact that you're throwing an exception means that it's not waiting for any existing exclusive or shareable locks to be released (this should be a blocking call). Make sure that you actually have the file-name correct, or check the error code in the boost::interprocess_exception
that is being thrown using either the what()
, get_native_error()
, or get_error_code()
methods. For instance, you could be having a file-permissions problem, or the file may not exist, etc. An exception is not thrown because of lock contention, so that's not your problem ...

Jason
- 31,834
- 7
- 59
- 78
-
The error thrown is file permissions. If we change the owner of the file we want to lock to the user attempting the lock, it works. Basically, I want two users to be able to lock the file in question, but obviously, only one user can own the file. – user788171 Aug 01 '11 at 18:22
-
Is there not a group-level permission you can set? For instance, on Linux/Unix, you can set the owner as well as the read/write/execute accessibility permissions for other users via `chown` and `chmod`. On Windows you have pretty fine-grained control via ACL's. – Jason Aug 02 '11 at 03:30