Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Deno.utimes() api #1948

Closed
axetroy opened this issue Mar 17, 2019 · 3 comments · Fixed by #2241
Closed

Feature Request: Deno.utimes() api #1948

axetroy opened this issue Mar 17, 2019 · 3 comments · Fixed by #2241

Comments

@axetroy
Copy link
Contributor

axetroy commented Mar 17, 2019

Deno.utimes() change the file system timestamps of the object referenced by path.

@ATheCoder
Copy link
Contributor

ATheCoder commented Apr 9, 2019

Node:

const fs = require("fs");

const new_atime = 1000000
const new_mtime = 1000000000

fs.utimes("./example", new_atime, new_mtime, (err) => {
    if (err) return console.log(err)
})

https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback

Rust:

standard library does not implement utimes, However there is a crate that does:

use std::fs::File;
use utime::*;

File::create("target/testdummy").unwrap();
set_file_times("target/testdummy", 1000000, 1000000000).unwrap();

let (accessed, modified) = get_file_times("target/testdummy").unwrap();
assert_eq!(accessed, 1000000);
assert_eq!(modified, 1000000000);

https://docs.rs/utime/0.2.2/utime/

Go:

mtime := time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC)
	atime := time.Date(2007, time.March, 2, 4, 5, 6, 0, time.UTC)
	if err := os.Chtimes("some-filename", atime, mtime); err != nil {
		log.Fatal(err)
	}

https://golang.org/pkg/os/ (search for func Chtimes)
### Ruby:
https://ruby-doc.org/core-2.2.0/File.html#method-c-utime
### Python:
https://docs.python.org/2/library/os.html (search for utime)

@ry
Copy link
Member

ry commented Apr 9, 2019

Cool - thanks for researching that. I'd say the interface should be:

namespace Deno {
  /** changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions. */
  function utime(filename: string, atime: number, mtime: number): Promise<void>;
  function utimeSync(filename: string, atime: number, mtime: number): void;
}

Any objections?

@kevinkassimo
Copy link
Contributor

Probably also allow changing just one of the 2 timestamps? (similar to what utimensat does)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants