aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-02-19 10:59:45 +0000
committerRon Yorston <rmy@pobox.com>2019-02-19 10:59:45 +0000
commit8c47a98c9166ff23c3bcbb3e1ef8430b349cf71e (patch)
treeaebfe98490659a3882dc2d391a15ea2d95c7e8b4
parent4d47580175918882dd827183569d6a50f460f00a (diff)
downloadbusybox-w32-8c47a98c9166ff23c3bcbb3e1ef8430b349cf71e.tar.gz
busybox-w32-8c47a98c9166ff23c3bcbb3e1ef8430b349cf71e.tar.bz2
busybox-w32-8c47a98c9166ff23c3bcbb3e1ef8430b349cf71e.zip
win32: stat(2) succeeds if fetching extra metadata fails
Some files can't be opened to fetch additional metadata. When that happens allow stat(2) to successfully return what data it has. In a few cases where the inode number is used to determine if files are identical ignore invalid inode numbers.
-rw-r--r--archival/tar.c8
-rw-r--r--editors/diff.c4
-rw-r--r--libbb/copy_file.c5
-rw-r--r--libbb/inode_hash.c5
-rw-r--r--win32/mingw.c14
5 files changed, 19 insertions, 17 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 54989b953..3375d1fe9 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -161,7 +161,7 @@ typedef struct TarBallInfo {
161# endif 161# endif
162 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */ 162 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
163 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */ 163 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
164#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA 164#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
165//TODO: save only st_dev + st_ino 165//TODO: save only st_dev + st_ino
166 struct stat tarFileStatBuf; /* Stat info for the tarball, letting 166 struct stat tarFileStatBuf; /* Stat info for the tarball, letting
167 * us know the inode and device that the 167 * us know the inode and device that the
@@ -529,12 +529,14 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
529 } 529 }
530 } 530 }
531 531
532#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA 532#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
533 /* It is a bad idea to store the archive we are in the process of creating, 533 /* It is a bad idea to store the archive we are in the process of creating,
534 * so check the device and inode to be sure that this particular file isn't 534 * so check the device and inode to be sure that this particular file isn't
535 * the new tarball */ 535 * the new tarball */
536 if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev 536 if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev
537 && tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino 537 && tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino
538 /* ignore invalid inode numbers */
539 && (ENABLE_FEATURE_EXTRA_FILE_DATA && statbuf->st_ino != 0)
538 ) { 540 ) {
539 bb_error_msg("%s: file is the archive; skipping", fileName); 541 bb_error_msg("%s: file is the archive; skipping", fileName);
540 return TRUE; 542 return TRUE;
@@ -707,7 +709,7 @@ static NOINLINE int writeTarFile(
707 709
708 /*tbInfo->hlInfoHead = NULL; - already is */ 710 /*tbInfo->hlInfoHead = NULL; - already is */
709 711
710#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA 712#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
711 /* Store the stat info for the tarball's file, so 713 /* Store the stat info for the tarball's file, so
712 * can avoid including the tarball into itself.... */ 714 * can avoid including the tarball into itself.... */
713 xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file"); 715 xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file");
diff --git a/editors/diff.c b/editors/diff.c
index 815c8a915..308d9782b 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -1040,7 +1040,9 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
1040 * 255, or if a local inode number (st_ino) exceeds 16777215. 1040 * 255, or if a local inode number (st_ino) exceeds 16777215.
1041 */ 1041 */
1042 if (ENABLE_DESKTOP 1042 if (ENABLE_DESKTOP
1043 && (!ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA) 1043 && (ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA)
1044 /* ignore invalid inode numbers */
1045 && (ENABLE_FEATURE_EXTRA_FILE_DATA && stb[0].st_ino != 0)
1044 && stb[0].st_ino == stb[1].st_ino 1046 && stb[0].st_ino == stb[1].st_ino
1045 && stb[0].st_dev == stb[1].st_dev 1047 && stb[0].st_dev == stb[1].st_dev
1046 && stb[0].st_size == stb[1].st_size 1048 && stb[0].st_size == stb[1].st_size
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index db7a00060..abe034f50 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -105,10 +105,11 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
105 return -1; 105 return -1;
106 } 106 }
107 } else { 107 } else {
108#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA 108#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA
109 /* MinGW does not have inode, and does not use device */
110 if (source_stat.st_dev == dest_stat.st_dev 109 if (source_stat.st_dev == dest_stat.st_dev
111 && source_stat.st_ino == dest_stat.st_ino 110 && source_stat.st_ino == dest_stat.st_ino
111 /* ignore invalid inode numbers */
112 && (ENABLE_FEATURE_EXTRA_FILE_DATA && source_stat.st_ino != 0)
112 ) { 113 ) {
113 bb_error_msg("'%s' and '%s' are the same file", source, dest); 114 bb_error_msg("'%s' and '%s' are the same file", source, dest);
114 return -1; 115 return -1;
diff --git a/libbb/inode_hash.c b/libbb/inode_hash.c
index 4142813e3..37fed9c82 100644
--- a/libbb/inode_hash.c
+++ b/libbb/inode_hash.c
@@ -61,6 +61,11 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
61 int i; 61 int i;
62 ino_dev_hashtable_bucket_t *bucket; 62 ino_dev_hashtable_bucket_t *bucket;
63 63
64#if ENABLE_FEATURE_EXTRA_FILE_DATA
65 /* ignore invalid inode numbers */
66 if (statbuf->st_ino == 0)
67 return;
68#endif
64 if (!name) 69 if (!name)
65 name = ""; 70 name = "";
66 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name)); 71 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
diff --git a/win32/mingw.c b/win32/mingw.c
index 3713fea95..84522d3ea 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -441,22 +441,14 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf)
441#if ENABLE_FEATURE_EXTRA_FILE_DATA 441#if ENABLE_FEATURE_EXTRA_FILE_DATA
442 fh = CreateFile(file_name, 0, 0, NULL, OPEN_EXISTING, 442 fh = CreateFile(file_name, 0, 0, NULL, OPEN_EXISTING,
443 FILE_FLAG_BACKUP_SEMANTICS, NULL); 443 FILE_FLAG_BACKUP_SEMANTICS, NULL);
444 if (fh == INVALID_HANDLE_VALUE) 444 if (fh != INVALID_HANDLE_VALUE &&
445 goto error; 445 GetFileInformationByHandle(fh, &hdata)) {
446
447 if (GetFileInformationByHandle(fh, &hdata)) {
448 buf->st_dev = hdata.dwVolumeSerialNumber; 446 buf->st_dev = hdata.dwVolumeSerialNumber;
449 buf->st_ino = hdata.nFileIndexLow | 447 buf->st_ino = hdata.nFileIndexLow |
450 (((ino_t)hdata.nFileIndexHigh)<<32); 448 (((ino_t)hdata.nFileIndexHigh)<<32);
451 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : hdata.nNumberOfLinks; 449 buf->st_nlink = S_ISDIR(buf->st_mode) ? 2 : hdata.nNumberOfLinks;
452 CloseHandle(fh);
453 }
454 else {
455 error:
456 errno = err_win_to_posix(GetLastError());
457 CloseHandle(fh);
458 return -1;
459 } 450 }
451 CloseHandle(fh);
460#endif 452#endif
461 453
462 /* 454 /*