File tree Expand file tree Collapse file tree 4 files changed +21
-33
lines changed Expand file tree Collapse file tree 4 files changed +21
-33
lines changed Original file line number Diff line number Diff line change 1- import contextlib
21import os
32import sys
4- from typing import Any , Generator , IO
3+ from typing import Any , Generator
54
65
76def perror (* errors : Any ) -> None :
@@ -11,17 +10,6 @@ def perror(*errors: Any) -> None:
1110 )
1211
1312
14- @contextlib .contextmanager
15- def safe_open (* args , ** kwargs ) -> Generator [IO | None ]:
16- try :
17- # pylint: disable=unspecified-encoding
18- with open (* args , ** kwargs ) as io :
19- yield io
20- except OSError as e :
21- perror (e )
22- yield None
23-
24-
2513def readlines_stdin () -> Generator [str ]:
2614 while line := sys .stdin .readline ():
2715 yield line
Original file line number Diff line number Diff line change @@ -54,11 +54,11 @@ def python_userland_sum(opts, args: list[str]) -> int:
5454 if name == "-" :
5555 print (SUM_ALGORITHMS [opts .algorithm ](sys .stdin .buffer .read ()))
5656 else :
57- with core . safe_open ( name , "rb" ) as io :
58- if not io :
59- failed = True
60- continue
61-
62- print ( f" { SUM_ALGORITHMS [ opts . algorithm ]( io . read ()) } { name } " )
57+ try :
58+ with open ( name , "rb" ) as f :
59+ print ( f" { SUM_ALGORITHMS [ opts . algorithm ]( f . read ()) } { name } " )
60+ except OSError as e :
61+ failed = True
62+ core . perror ( e )
6363
6464 return int (failed )
Original file line number Diff line number Diff line change @@ -34,11 +34,11 @@ def python_userland_sync(opts, args: list[str]) -> int:
3434 failed = False
3535
3636 for name in tqdm (args , ascii = True , desc = "Syncing files" ) if opts .progress else args :
37- with core . safe_open ( name , "rb+" ) as io :
38- if not io :
39- failed = True
40- continue
41-
42- os . fsync ( io )
37+ try :
38+ with open ( name , "rb+" ) as f :
39+ os . fsync ( f )
40+ except OSError as e :
41+ failed = True
42+ core . perror ( e )
4343
4444 return int (failed )
Original file line number Diff line number Diff line change @@ -114,13 +114,13 @@ def python_userland_truncate(opts, args: list[str]) -> int:
114114 if new_size == old_size :
115115 continue
116116
117- with core . safe_open ( file , "rb+" ) as io :
118- if not io :
119- failed = True
120- continue
121-
122- io . truncate (
123- new_size * stat . st_blksize if opts . io_blocks else new_size ,
124- )
117+ try :
118+ with open ( file , "rb+" ) as f :
119+ f . truncate (
120+ new_size * stat . st_blksize if opts . io_blocks else new_size ,
121+ )
122+ except OSError as e :
123+ failed = True
124+ core . perror ( e )
125125
126126 return int (failed )
You can’t perform that action at this time.
0 commit comments