From 8c47a98c9166ff23c3bcbb3e1ef8430b349cf71e Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 19 Feb 2019 10:59:45 +0000 Subject: 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. --- libbb/copy_file.c | 5 +++-- libbb/inode_hash.c | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'libbb') 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) return -1; } } else { -#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA - /* MinGW does not have inode, and does not use device */ +#if ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA if (source_stat.st_dev == dest_stat.st_dev && source_stat.st_ino == dest_stat.st_ino + /* ignore invalid inode numbers */ + && (ENABLE_FEATURE_EXTRA_FILE_DATA && source_stat.st_ino != 0) ) { bb_error_msg("'%s' and '%s' are the same file", source, dest); 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 * int i; ino_dev_hashtable_bucket_t *bucket; +#if ENABLE_FEATURE_EXTRA_FILE_DATA + /* ignore invalid inode numbers */ + if (statbuf->st_ino == 0) + return; +#endif if (!name) name = ""; bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name)); -- cgit v1.2.3-55-g6feb