mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
std: Do size compare based on fstat after opening the files.
CID: #996804 Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
5d34417e76
commit
35461db4e9
1 changed files with 18 additions and 16 deletions
|
@ -227,22 +227,6 @@ int c_compare_file( const char *f1, const char *f2 ) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* compare size first. */
|
||||
rc = _tstat(wf1, &stat1);
|
||||
if(rc< 0) {
|
||||
goto out;
|
||||
}
|
||||
rc = _tstat(wf2, &stat2);
|
||||
if(rc < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* if sizes are different, the files can not be equal. */
|
||||
if( stat1.st_size != stat2.st_size ) {
|
||||
rc = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
_fmode = _O_BINARY;
|
||||
#endif
|
||||
|
@ -252,12 +236,30 @@ int c_compare_file( const char *f1, const char *f2 ) {
|
|||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd2 = _topen(wf2, O_RDONLY);
|
||||
if(fd2 < 0) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* compare size first. */
|
||||
rc = fstat(fd1, &stat1);
|
||||
if (rc < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = fstat(fd2, &stat2);
|
||||
if (rc < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* if sizes are different, the files can not be equal. */
|
||||
if (stat1.st_size != stat2.st_size) {
|
||||
rc = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
while( (size1 = read(fd1, buffer1, BUFFER_SIZE)) > 0 ) {
|
||||
size2 = read( fd2, buffer2, BUFFER_SIZE );
|
||||
|
||||
|
|
Loading…
Reference in a new issue