| Conditions | 5 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | import os |
||
| 12 | def main(log_printer=None, section: Section=None): |
||
| 13 | start_path = get_config_directory(section) |
||
| 14 | log_printer = log_printer or LogPrinter(ConsolePrinter()) |
||
| 15 | |||
| 16 | if start_path is None: |
||
| 17 | return 255 |
||
| 18 | |||
| 19 | # start_path may have unintended glob characters |
||
| 20 | orig_files = Globbing.glob(os.path.join( |
||
| 21 | glob_escape(start_path), '**', '*.orig')) |
||
| 22 | |||
| 23 | not_deleted = 0 |
||
| 24 | for ofile in orig_files: |
||
| 25 | log_printer.info("Deleting old backup file... " |
||
| 26 | + os.path.relpath(ofile)) |
||
| 27 | try: |
||
| 28 | os.remove(ofile) |
||
| 29 | except OSError as oserror: |
||
| 30 | not_deleted += 1 |
||
| 31 | log_printer.warn("Couldn't delete {}. {}".format( |
||
| 32 | os.path.relpath(ofile), oserror.strerror)) |
||
| 33 | |||
| 34 | if not_deleted: |
||
| 35 | log_printer.warn(str(not_deleted) + " .orig backup files could not be" |
||
| 36 | " deleted, possibly because you lack the permission" |
||
| 37 | " to do so. coala may not be able to create" |
||
| 38 | " backup files when patches are applied.") |
||
| 39 | return 0 |
||
| 40 |