Skip to content

Commit

Permalink
Fixup changeset atomicity
Browse files Browse the repository at this point in the history
Another fixup.
  • Loading branch information
dmnks committed Dec 25, 2023
1 parent d09226e commit 0213eaa
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions devel_doc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,10 @@ def _data_file(self, number):
return '/dev/null'
return '{}/{}'.format(self.number_dir, number)

def _link_file(self, commit, base_only=False):
def _link_file(self, commit):
if len(commit) < SHA1_LEN:
commit = shell('git rev-parse {}'.format(commit))
base = '{}/{}'.format(self.commit_dir, commit[:2])
if base_only:
return base
return '{}/{}'.format(base, commit[2:])
return '{}/{}/{}'.format(self.commit_dir, commit[:2], commit[2:])

def _fetch(self, commit):
data = shell('gh pr list --state merged --limit 1 --json '
Expand Down Expand Up @@ -180,21 +177,23 @@ def __setitem__(self, key, data):

data_file = self._data_file(number)
link_file = self._link_file(key)
link_base = self._link_file(key, True)

# Ensure the write is atomic in case of SIGINT
done = False
excp = None
while not done:
try:
with open(data_file, 'w') as f:
f.write(entry)
if os.path.islink(link_file):
os.unlink(link_file)
os.makedirs(link_base, exist_ok=True)
os.makedirs(os.path.dirname(link_file), exist_ok=True)
os.symlink(target, link_file)
done = True
except KeyboardInterrupt:
except KeyboardInterrupt as excp:
continue
if excp is not None:
raise excp

def __getitem__(self, key):
ret = {}
Expand Down

0 comments on commit 0213eaa

Please sign in to comment.