Skip to content

Commit dc76109

Browse files
synaretephlogistonjohn
authored andcommitted
sambacc: use fchmod + fsync via directory fd
Manipulate directory via file-descriptor (instead of path) to ensure that 'fchmod(2)' system call is flushed all the way into stable storage with additional 'fsync(2)'. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 414093f commit dc76109

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sambacc/permissions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ def _set_perms(self) -> None:
145145
# yeah, this is really simple compared to all the state management
146146
# stuff.
147147
path = self._full_path()
148-
os.chmod(path, self._mode, follow_symlinks=False)
148+
dfd = os.open(path, os.O_DIRECTORY)
149+
try:
150+
os.fchmod(dfd, self._mode)
151+
os.fsync(dfd)
152+
except OSError:
153+
os.sync()
154+
finally:
155+
os.close(dfd)
149156

150157
def _timestamp(self) -> str:
151158
return datetime.datetime.now().strftime("%s")

0 commit comments

Comments
 (0)