From owner-freebsd-current@FreeBSD.ORG Wed Aug 29 07:41:20 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3AB8C106566B; Wed, 29 Aug 2012 07:41:20 +0000 (UTC) (envelope-from gljennjohn@googlemail.com) Received: from mail-bk0-f54.google.com (mail-bk0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 8D7C28FC0A; Wed, 29 Aug 2012 07:41:19 +0000 (UTC) Received: by bkcje9 with SMTP id je9so159940bkc.13 for ; Wed, 29 Aug 2012 00:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references:reply-to :x-mailer:mime-version:content-type:content-transfer-encoding; bh=GJJRMt3rlQdfAo90jVMb4JOLa5t/rfY/vCCcQ85zmPU=; b=l16ZAlc+YHvMMNGsOKwN8oynFurRIWBA3bsq6eab7aTrWa1FzUcHb63254Sq3ZM0v0 mDQCJq6RvPCm5emuTeL2P6JF9kO33mz/9WdOfgjxm6DlY+xL6RE+07iabq27NHxIIE8o ViNQuvKEFbHnl8+RAffsk/ScXQd/IvSmTM2kUIm4PJWs8Gt1+ywHrO7M5jX/lUfti98I 33OjSFPeqv5835pVsRxpxm4VSXM1bWWi0pzGVxf3HjtZ9C3Qsz4wkpu6GSG73YDIDxZ2 8bGX6emo5+9mbWVOdpG8ncUosxEhZldxchpmOf9JSaeVRZ2hm5PQ9pQBF4UP8MMA6KkP a1AA== Received: by 10.204.151.81 with SMTP id b17mr292267bkw.95.1346226078420; Wed, 29 Aug 2012 00:41:18 -0700 (PDT) Received: from ernst.jennejohn.org (p578E2FC5.dip.t-dialin.net. [87.142.47.197]) by mx.google.com with ESMTPS id t23sm14203650bks.4.2012.08.29.00.41.16 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Aug 2012 00:41:17 -0700 (PDT) Date: Wed, 29 Aug 2012 09:41:15 +0200 From: Gary Jennejohn To: John Baldwin Message-ID: <20120829094115.3a40d35f@ernst.jennejohn.org> In-Reply-To: <201208281058.10029.jhb@freebsd.org> References: <201208281058.10029.jhb@freebsd.org> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.6; amd64-portbld-freebsd10.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: current@freebsd.org Subject: Re: [PATCH] Add a "-h" flag to mv X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: gljennjohn@googlemail.com List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Aug 2012 07:41:20 -0000 On Tue, 28 Aug 2012 10:58:09 -0400 John Baldwin wrote: > I have a use case at work where I need to be able to update a symlink that > points to a directory atomically (so that it points to a new directory). To > give a conrete example, suppose I have two directories 'foo' and 'bar', and a > symlink 'a' that I wish to atomically flip from 'foo' to 'bar'. > > Using 'ln -shf bar a' is not atomic as it uses separate unlink() and symlink() > system calls, so there is a race where another thread may encounter ENOENT > while traversing 'a'. > > The approach we used was to create a new symbolic link 'a.new' (e.g. via > 'ln -s bar a.new') and then use rename() to rename 'a.new' on top of 'a'. > Normally to do an atomic rename from userland one would use 'mv', but > 'mv a.new a' doesn't do that. Instead, it moves 'a.new' into the directory > referenced by the 'a' symlink. At work we have resorted to invoking python's > os.rename() in a one-liner to handle this. > > While rehashing this discussion today it occurred to me that a -h flag to > mv would allow it to work in this case (and is very similar to how ln treats > its -h flag). To that end, I have a patch to add a new -h flag to mv that > allows one to atomically update a symlink that points to a directory. I > could not find any other mv commands that have adopted a -h (or a different > flag that accomplishes the same task). Given that it functions identically > to the -h flag for ln, -h seemed the "logical" choice. Any objections? > [snip patch] Nope, seems like a reasonable extension to me (gj@). -- Gary Jennejohn