From 616adc22e109874038ed6b9d1f0d83b3ae0fcbc4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 15 Oct 2022 20:18:20 -0700 Subject: [PATCH] Support Linux < 3.6 --- native/src/base/files.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index df820655a..6fae3224a 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -82,19 +82,19 @@ pub fn realpath(path: &CStr, buf: &mut [u8]) -> isize { if let Some(fd) = open_fd!(path, O_PATH | O_CLOEXEC) { let mut st1: libc::stat; let mut st2: libc::stat; + let mut skip_check = false; unsafe { st1 = std::mem::zeroed(); if libc::fstat(fd.as_raw_fd(), &mut st1) < 0 { - *errno() = ENOENT; - return -1; + // This shall only fail on Linux < 3.6 + skip_check = true; } } let len = fd_path(fd.as_raw_fd(), buf); unsafe { st2 = std::mem::zeroed(); if libc::stat(buf.as_ptr().cast(), &mut st2) < 0 - || st2.st_dev != st1.st_dev - || st2.st_ino != st1.st_ino + || (!skip_check && (st2.st_dev != st1.st_dev || st2.st_ino != st1.st_ino)) { *errno() = ENOENT; return -1;