Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
4df7253c
Commit
4df7253c
authored
Dec 29, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out locking primitives
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
2ed7f414
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
weblate/trans/filelock.py
weblate/trans/filelock.py
+12
-4
No files found.
weblate/trans/filelock.py
View file @
4df7253c
...
...
@@ -61,6 +61,14 @@ class FileLock(object):
"""Opens lock file"""
return
os
.
open
(
self
.
lockfile
,
os
.
O_CREAT
|
os
.
O_WRONLY
)
def
try_lock
(
self
,
handle
):
"""Tries to lock the file"""
fcntl
.
flock
(
handle
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
def
unlock
(
self
,
handle
):
"""Unlocks lock"""
fcntl
.
flock
(
handle
,
fcntl
.
LOCK_UN
)
def
acquire
(
self
):
"""
Acquire the lock, if possible.
...
...
@@ -81,7 +89,7 @@ class FileLock(object):
# Try to acquire lock
while
True
:
try
:
fcntl
.
flock
(
self
.
handle
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
self
.
try_lock
(
self
.
handle
)
break
except
IOError
as
error
:
if
error
.
errno
not
in
[
errno
.
EACCES
,
errno
.
EAGAIN
]:
...
...
@@ -100,8 +108,8 @@ class FileLock(object):
'''
handle
=
self
.
open_file
()
try
:
fcntl
.
flock
(
handle
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
fcntl
.
flock
(
handle
,
fcntl
.
LOCK_UN
)
self
.
try_lock
(
handle
)
self
.
unlock
(
handle
)
return
False
except
IOError
as
error
:
if
error
.
errno
not
in
[
errno
.
EACCES
,
errno
.
EAGAIN
]:
...
...
@@ -113,7 +121,7 @@ class FileLock(object):
Release the lock and delete underlaying file.
"""
if
self
.
is_locked
:
fcntl
.
flock
(
self
.
handle
,
fcntl
.
LOCK_UN
)
self
.
unlock
(
self
.
handle
)
os
.
close
(
self
.
handle
)
self
.
handle
=
None
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment