@@ -59,29 +59,41 @@ def file_checksum(filename):
59
59
return hashlib .sha1 (file_handle .read ()).hexdigest ()
60
60
61
61
def check_group (group_name , files , master_file_picker , emit_error ):
62
- checksums = {file_checksum (f ) for f in files }
62
+ extant_files = [f for f in files if path .isfile (f )]
63
+ if len (extant_files ) == 0 :
64
+ emit_error (__file__ , 0 , "No files found from group '" + group_name + "'." )
65
+ emit_error (__file__ , 0 ,
66
+ "Create one of the following files, and then run this script with "
67
+ "the --latest switch to sync it to the other file locations." )
68
+ for filename in files :
69
+ emit_error (__file__ , 0 , " " + filename )
70
+ return
71
+
72
+ checksums = {file_checksum (f ) for f in extant_files }
63
73
64
- if len (checksums ) == 1 :
74
+ if len (checksums ) == 1 and len (extant_files ) == len (files ):
75
+ # All files are present and identical.
65
76
return
66
77
67
- master_file = master_file_picker (files )
78
+ master_file = master_file_picker (extant_files )
68
79
if master_file is None :
69
80
emit_error (__file__ , 0 ,
70
81
"Files from group '" + group_name + "' not in sync." )
71
82
emit_error (__file__ , 0 ,
72
83
"Run this script with a file-name argument among the "
73
84
"following to overwrite the remaining files with the contents "
74
- "of that file or run with the --latest switch to update each "
85
+ "of that file, or run with the --latest switch to update each "
75
86
"group of files from the most recently modified file in the group." )
76
- for filename in files :
87
+ for filename in extant_files :
77
88
emit_error (__file__ , 0 , " " + filename )
78
89
else :
79
90
print (" Syncing others from" , master_file )
80
91
for filename in files :
81
92
if filename == master_file :
82
93
continue
83
94
print (" " + filename )
84
- os .replace (filename , filename + '~' )
95
+ if path .isfile (filename ):
96
+ os .replace (filename , filename + '~' )
85
97
shutil .copy (master_file , filename )
86
98
print (" Backups written with '~' appended to file names" )
87
99
0 commit comments