http://www.perlmonks.org?node_id=1017127


in reply to Re: why does open ">..." sometimes touches the directory?
in thread why does open ">..." sometimes touches the directory?

That's right. As I said, the "open" that I am doing, is only _sometimes_ modifying the directory. I don't know why.

I would respectfully disagree with what some of the other Monks seem to be saying, is that overwriting a file, must touch the directory. As shown below.

the question is, why do my Perl scripts sometimes do it and sometimes don't - and I checked, all they do explicitly, is open for writing, and write, and close, not remove anything

The reason I care, is because I am a makefiles guy. As such, I don't want to touch _anything_ that does not need absolutely need to be touched, so that the system does not rebuild too much. Yes I do have dependencies on directories (meaning, their contents listing). When I do Perl scripts, sometimes, they will open an existing file for writing, and the directory gets touched. That's bad for me.

mgaleck{262}: touch test/foobar mgaleck{263}: ls -ld test drwxr-xr-x 2 mgaleck sw-team 138 Feb 5 03:30 test mgaleck{264}: date Tue Feb 5 03:31:12 PST 2013 mgaleck{265}: echo foobar > test/foobar mgaleck@hq1-up-swe-07{266}: ls -ld test drwxr-xr-x 2 mgaleck sw-team 138 Feb 5 03:30 test

Replies are listed 'Best First'.
Re^3: why does open ">..." sometimes touches the directory?
by parv (Parson) on Feb 05, 2013 at 11:50 UTC

    Same does not happen on FreeBSD 8.3-STABLE when tried in zsh 4.3.10 & tcsh 6.18.01 (Astron) 2012-02-14 ...

    mkdir -p ./tmp/test ; ll -d ./tmp/test ; sleep 60 ; echo > ./tmp/test/ +file ; ll -d ./tmp/test drwx------ 2 parv people 512 Feb 5 01:48 ./tmp/test/ drwx------ 2 parv people 512 Feb 5 01:49 ./tmp/test/

    ... got the same result when directory was created in /tmp. I have to say I would be (rudely) surprised if the directory modification time did not change after a file was created.

Re^3: why does open ">..." sometimes touches the directory?
by Anonymous Monk on Feb 05, 2013 at 11:45 UTC

    the question is, why do my Perl scripts sometimes do it and sometimes don't - and I checked, all they do explicitly, is open for writing, and write, and close, not remove anything

    Maybe they use rename, maybe they use utime, maybe they call other functions or programs that do manage to change mtime, .... you seem to think open is responsible, but it probably isn't

Re^3: why does open ">..." sometimes touches the directory?
by Anonymous Monk on Feb 05, 2013 at 13:30 UTC

    On my NTFS windows machine, create modifies directory, delete modifies directory, but not append or clobber

    However updating mtime after delete is not immediate, it is delayed (I assume a seeking optimization)