@@ -121,14 +121,15 @@ bool DoInstallFiles ( void )
121121 // Copy current(old) files into backup location
122122 for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
123123 {
124- if ( !FileCopy ( itemList[i].strDestPathFilename , itemList[i].strBackupPathFilename ) )
124+ const SFileItem& item = itemList[i];
125+ if ( !FileCopy ( item.strDestPathFilename , item.strBackupPathFilename ) )
125126 {
126- if ( FileExists ( itemList[i] .strDestPathFilename ) )
127+ if ( FileExists ( item .strDestPathFilename ) )
127128 {
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 ) );
129130 return false ;
130131 }
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 ) );
132133 }
133134 }
134135
@@ -137,30 +138,40 @@ bool DoInstallFiles ( void )
137138 std::vector < SFileItem > fileListSuccess;
138139 for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
139140 {
140- if ( !FileCopy ( itemList[i].strSrcPathFilename , itemList[i].strDestPathFilename ) )
141+ const SFileItem& item = itemList[i];
142+ if ( !FileCopy ( item.strSrcPathFilename , item.strDestPathFilename ) )
141143 {
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+ }
145151 }
146- fileListSuccess.push_back ( itemList[i] );
152+ fileListSuccess.push_back ( item );
147153 }
148154
149155 // If fail, copy back old files
150156 if ( !bOk )
151157 {
152158 bool bPossibleDisaster = false ;
153- for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
159+ for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
154160 {
161+ const SFileItem& item = fileListSuccess[i];
155162 int iRetryCount = 3 ;
156163 while ( true )
157164 {
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 ) )
159170 break ;
160171
161172 if ( !--iRetryCount )
162173 {
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 ) );
164175 bPossibleDisaster = true ;
165176 break ;
166177 }
0 commit comments