]> git.lizzy.rs Git - rust.git/commitdiff
minor fixes and updated docs
authorChristian Poveda <git@christianpoveda.xyz>
Thu, 26 Dec 2019 17:12:19 +0000 (12:12 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Thu, 26 Dec 2019 17:12:27 +0000 (12:12 -0500)
src/shims/fs.rs

index 3084d977de82aac26d5c2d5ebb568d65812dba4c..f4a792a0410c6c9e89793debc7d887afd4dcf12f 100644 (file)
@@ -411,9 +411,9 @@ fn statx(
 
         // If the `AT_SYMLINK_NOFOLLOW` flag is set, we query the file's metadata without following
         // symbolic links.
-        let is_symlink = flags & this.eval_libc("AT_SYMLINK_NOFOLLOW")?.to_i32()? != 0;
+        let follow_symlink = flags & this.eval_libc("AT_SYMLINK_NOFOLLOW")?.to_i32()? == 0;
 
-        let status = match FileStatus::new(this, path, is_symlink)? {
+        let status = match FileStatus::new(this, path, follow_symlink)? {
             Some(status) => status,
             None => return Ok(-1),
         };
@@ -428,6 +428,8 @@ fn statx(
             .try_into()
             .unwrap_or_else(|_| bug!("libc contains bad value for constant"));
 
+        // We need to set the corresponding bits of `mask` if the access, creation and modification
+        // times were available. Otherwise we let them be zero.
         let (access_sec, access_nsec) = status.accessed.map(|tup| {
             mask |= this.eval_libc("STATX_ATIME")?.to_u32()?;
             InterpResult::Ok(tup)
@@ -497,9 +499,12 @@ fn handle_not_found<T: From<i32>>(&mut self) -> InterpResult<'tcx, T> {
     }
 }
 
-// Extracts the number of seconds and nanoseconds elapsed between `time` and the unix epoch when
-// `time` is Ok. If `time` is an error, it returns `None`.
-fn extract_sec_and_nsec<'tcx>(time: std::io::Result<SystemTime>) -> InterpResult<'tcx, Option<(u64, u32)>> {
+/// Extracts the number of seconds and nanoseconds elapsed between `time` and the unix epoch when
+/// `time` is Ok. Returns `None` if `time` is an error. Fails if `time` happens before the unix
+/// epoch.
+fn extract_sec_and_nsec<'tcx>(
+    time: std::io::Result<SystemTime>
+) -> InterpResult<'tcx, Option<(u64, u32)>> {
     time.ok().map(|time| {
         let duration = system_time_to_duration(&time)?;
         Ok((duration.as_secs(), duration.subsec_nanos()))
@@ -518,9 +523,9 @@ impl FileStatus {
     fn new<'tcx, 'mir>(
         ecx: &mut MiriEvalContext<'mir, 'tcx>,
         path: PathBuf,
-        is_symlink: bool
+        follow_symlink: bool
     ) -> InterpResult<'tcx, Option<FileStatus>> {
-        let metadata = if is_symlink {
+        let metadata = if follow_symlink {
             // FIXME: metadata for symlinks need testing.
             std::fs::symlink_metadata(path)
         } else {