Skip to content

Commit d8b544d

Browse files
committed
sync: Add sync.py
1 parent 9e1ec73 commit d8b544d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/sync.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python3
2+
3+
import os
4+
import sys
5+
from optparse import OptionParser
6+
7+
8+
def lazybox_sync(_, filenames: list[str]):
9+
if filenames:
10+
failed = False
11+
12+
for name in filenames:
13+
try:
14+
with open(name, "r+") as io:
15+
os.fsync(io)
16+
except OSError as e:
17+
failed = True
18+
print(e, file=sys.stderr)
19+
20+
if failed:
21+
sys.exit(1)
22+
else:
23+
os.sync()
24+
25+
26+
if __name__ == "__main__":
27+
parser = OptionParser(
28+
usage="Usage: %prog [FILE]...",
29+
description="Sync the filesystem or write each FILE's blocks to disk.",
30+
add_help_option=False,
31+
)
32+
parser.add_option("--help", action="help", help="show usage information and exit")
33+
34+
lazybox_sync(*parser.parse_args())

0 commit comments

Comments
 (0)