|
From: | Eric Blake |
Subject: | bug#9742: touch option for existence? |
Date: | Thu, 13 Oct 2011 08:09:13 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.4 Thunderbird/3.1.15 |
On 10/13/2011 03:05 AM, Pádraig Brady wrote:
Note the above is easier to express in shell like: [ -e "$file" ] || touch "$file" But that is racy. If you were using touch for locking purposes then adding -e (must create), would allow one to add O_EXCL to the open(),
You can avoid that race, while still accomplishing your goal of creating the file if it does not exist, all without corrupting timestamps if it does exist, by using straight shell:
(set -C; : > "$file") 2>/dev/null || : -- Eric Blake address@hidden +1-801-349-2682 Libvirt virtualization library http://libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |