File: utimes.ml

package info (click to toggle)
js-of-ocaml 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (38 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(* TEST
 include unix;
 readonly_files = "utimes.txt";
 hasunix;
 {
   bytecode;
 }{
   native;
 }
*)

(* We do not check setting the "last access time" because it is hard to do so on
   some file systems. FAT, for example, only has a 1d resolution for this
   timestamp, and even NTFS can potentially delay the update of this timestamp
   by up to an hour.
*)

let txt = "utimes.txt"

(* To account for filesystems with large timestamp resolution (e.g. FAT - 2
   seconds for mtime)
*)
let close s t =
  abs_float (s -. t) < 10.

let check tm =
  let tm' = (Unix.stat txt).Unix.st_mtime in
  Printf.printf "tm ~ tm' (%B)\n" (close tm tm')

let () =
  let oc = open_out_bin txt in
  close_out oc;
  let tm = 1508391026.124 in
  Unix.utimes txt tm tm;
  check tm;
  let tn = Unix.time () in
  Unix.utimes txt 0. 0.;
  check tn