Recently I was working on the refactory of the resource building process of our site with
Grunt. I came across a problem that the
grunt.file.copydid not provide an option to preserve the timestamp(
mtime) of file or directory. So I had to implement it myself. I made a research on when will the mtime of a directory be changed, the conclusion as follows.
A directory is a special kind of file; its contents is a set of (filename, i-node) tuples. Thus directory’s
mtime is updated whenever a tuple(file or subdirectory) is
- Modifying the contents of a file within the directory does not change the directory itself, nor does updating the
mtimeof a file or a subdirectory.
- When file’s metadata changes (owner, group, mode,
mtime- hosted in i-node), directory’s
mtimeis NOT updated (neither on the file nor containing directory) but the file’s
mtimeof a subdirectory will not influence the containing directory unless the subdirectory’s is
renamed. So that is said
mtimeof a subdirectory will not bubbled to the root.