Skip to content

Commit

Permalink
minor fix: address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
i10416 committed Jan 3, 2023
1 parent 99aad5d commit 7ec4eac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion javalib/src/main/scala/java/io/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,10 @@ class File(_path: String) extends Serializable with Comparable[File] {
MinWinBaseApiOps.FileTimeOps.toUnixEpochMillis(!lastModified)
}
} else {
import scala.scalanative.posix.sys.statOps.statOps
val buf = alloc[stat.stat]()
if (stat.stat(toCString(path), buf) == 0) {
buf._8._1 * 1000L
buf.st_mtime * 1000L
} else {
0L
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ final class PosixFileAttributeViewImpl(path: Path, options: Array[LinkOption])
lastAccessTime: FileTime,
createTime: FileTime
): Unit = Zone { implicit z =>
import scala.scalanative.posix.sys.statOps.statOps
val sb = getStat()

val buf = alloc[utime.utimbuf]()
buf._1 =
if (lastAccessTime != null) lastAccessTime.to(TimeUnit.SECONDS).toSize
else sb._7._1
else sb.st_atime
buf._2 =
if (lastModifiedTime != null) lastModifiedTime.to(TimeUnit.SECONDS).toSize
else sb._8._1
else sb.st_mtime
// createTime is ignored: No posix-y way to set it.
if (utime.utime(toCString(path.toString), buf) != 0)
throwIOException()
Expand Down
2 changes: 1 addition & 1 deletion posixlib/src/main/resources/scala-native/sys/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void scalanative_stat_init(struct stat *stat,
my_stat->st_atim = stat->st_atim;
my_stat->st_mtim = stat->st_mtim;
my_stat->st_ctim = stat->st_ctim;
#else
#else // APPLE
my_stat->st_atim = stat->st_atimespec;
my_stat->st_mtim = stat->st_mtimespec;
my_stat->st_ctim = stat->st_ctimespec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,13 @@ object statOps {
def st_nlink_=(nlink: nlink_t): Unit = c._12 = nlink
def st_mode: mode_t = c._13
def st_mode_=(mode: mode_t): Unit = c._13 = mode

// helpers for Non POSIX(most likely Apple) st_* equivalents
def st_atimespec: timespec = c._7
def st_atimespec_=(t: timespec): Unit = c._7 = t
def st_mtimespec: timespec = c._8
def st_mtimespec_=(t: timespec): Unit = c._8 = t
def st_ctimespec: timespec = c._9
def st_ctimespec_=(t: timespec): Unit = c._9 = t
}
}

0 comments on commit 7ec4eac

Please sign in to comment.