@@ -121,14 +121,15 @@ bool DoInstallFiles ( void )
121
121
// Copy current(old) files into backup location
122
122
for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
123
123
{
124
- if ( !FileCopy ( itemList[i].strDestPathFilename , itemList[i].strBackupPathFilename ) )
124
+ const SFileItem& item = itemList[i];
125
+ if ( !FileCopy ( item.strDestPathFilename , item.strBackupPathFilename ) )
125
126
{
126
- if ( FileExists ( itemList[i] .strDestPathFilename ) )
127
+ if ( FileExists ( item .strDestPathFilename ) )
127
128
{
128
- AddReportLog ( 5021 , SString ( " InstallFiles: Couldn't backup '%s' to '%s'" , itemList[i] .strDestPathFilename . c_str (), itemList[i] .strBackupPathFilename . c_str () ) );
129
+ AddReportLog ( 5021 , SString ( " InstallFiles: Couldn't backup '%s' to '%s'" , *item .strDestPathFilename , *item .strBackupPathFilename ) );
129
130
return false ;
130
131
}
131
- AddReportLog ( 4023 , SString ( " InstallFiles: Couldn't backup '%s' as it does not exist" , itemList[i] .strDestPathFilename . c_str () ) );
132
+ AddReportLog ( 4023 , SString ( " InstallFiles: Couldn't backup '%s' as it does not exist" , *item .strDestPathFilename ) );
132
133
}
133
134
}
134
135
@@ -137,30 +138,40 @@ bool DoInstallFiles ( void )
137
138
std::vector < SFileItem > fileListSuccess;
138
139
for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
139
140
{
140
- if ( !FileCopy ( itemList[i].strSrcPathFilename , itemList[i].strDestPathFilename ) )
141
+ const SFileItem& item = itemList[i];
142
+ if ( !FileCopy ( item.strSrcPathFilename , item.strDestPathFilename ) )
141
143
{
142
- AddReportLog ( 5022 , SString ( " InstallFiles: Couldn't copy '%s' to '%s'" , itemList[i].strSrcPathFilename .c_str (), itemList[i].strDestPathFilename .c_str () ) );
143
- bOk = false ;
144
- break ;
144
+ // If copy failed, check if we really need to copy the file
145
+ if ( GenerateSha256HexStringFromFile ( item.strSrcPathFilename ) != GenerateSha256HexStringFromFile ( item.strDestPathFilename ) )
146
+ {
147
+ AddReportLog ( 5022 , SString ( " InstallFiles: Couldn't copy '%s' to '%s'" , *item.strSrcPathFilename , *item.strDestPathFilename ) );
148
+ bOk = false ;
149
+ break ;
150
+ }
145
151
}
146
- fileListSuccess.push_back ( itemList[i] );
152
+ fileListSuccess.push_back ( item );
147
153
}
148
154
149
155
// If fail, copy back old files
150
156
if ( !bOk )
151
157
{
152
158
bool bPossibleDisaster = false ;
153
- for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
159
+ for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
154
160
{
161
+ const SFileItem& item = fileListSuccess[i];
155
162
int iRetryCount = 3 ;
156
163
while ( true )
157
164
{
158
- if ( FileCopy ( fileListSuccess[i].strBackupPathFilename , fileListSuccess[i].strDestPathFilename ) )
165
+ if ( FileCopy ( item.strBackupPathFilename , item.strDestPathFilename ) )
166
+ break ;
167
+
168
+ // If copy failed, check if we really need to copy the file
169
+ if ( GenerateSha256HexStringFromFile ( item.strBackupPathFilename ) != GenerateSha256HexStringFromFile ( item.strDestPathFilename ) )
159
170
break ;
160
171
161
172
if ( !--iRetryCount )
162
173
{
163
- AddReportLog ( 5023 , SString ( " InstallFiles: Possible disaster restoring '%s' to '%s'" , itemList[i] .strBackupPathFilename . c_str (), itemList[i] .strDestPathFilename . c_str () ) );
174
+ AddReportLog ( 5023 , SString ( " InstallFiles: Possible disaster restoring '%s' to '%s'" , *item .strBackupPathFilename , *item .strDestPathFilename ) );
164
175
bPossibleDisaster = true ;
165
176
break ;
166
177
}
0 commit comments