Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lieer/gmailieer.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ def main(self):
if args.quiet:
args.no_progress = True

args.func(args)
try:
args.func(args)
except Local.LockingException as e:
print(e, file=sys.stderr)
sys.exit(7)

def initialize(self, args):
self.setup(args, False)
Expand Down
16 changes: 12 additions & 4 deletions lieer/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import base64
import errno
import fcntl
import json
import os
Expand Down Expand Up @@ -116,6 +117,9 @@ def update_translation_list_with_overlay(self, translation_list_overlay):
class RepositoryException(Exception):
pass

class LockingException(RepositoryException):
pass

class Config:
replace_slash_with_dot = False
account = None
Expand Down Expand Up @@ -382,10 +386,14 @@ def load_repository(self, block=False):
fcntl.lockf(self.lckf, fcntl.LOCK_EX)
else:
fcntl.lockf(self.lckf, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
raise Local.RepositoryException(
"failed to lock repository (probably in use by another gmi instance)"
)
except OSError as e:
if e.errno in (errno.EACCES, errno.EAGAIN):
# Lock already taken, works as intended
raise Local.LockingException(
"failed to lock repository (probably in use by another gmi instance)"
) from None
# otherwise probably irrecoverable, keep the raw exception to help debugging
raise

self.config = Local.Config(self.config_f)
self.state = Local.State(self.state_f, self.config)
Expand Down
Loading