delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/02/21/06:45:47

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Tue, 21 Feb 2012 12:45:00 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: sed 4.2.1-1 locks files on windows
Message-ID: <20120221114500.GF22597@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <20120221105805 DOT 256390 AT gmx DOT net>
MIME-Version: 1.0
In-Reply-To: <20120221105805.256390@gmx.net>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Feb 21 11:58, cygwin DOT com AT munub DOT e4ward DOT com wrote:
> see here: http://stackoverflow.com/questions/9368783/cygwin-bash-sed-locks-my-files
> 
> When I change files in cygwin bash with the sed command, the file gets locked.
> 
> Reproduce:
> 
>     Open cmd and cd to non-user directory (f.e. temp)
>     echo aaa > test.txt
>     Open in texteditor, add line, try to save => works
>     %CYGWIN_HOME%\bin\bash -c "sed -i 's/aaa/bbb/' test.txt
>     In texteditor, add another line and try to save => "Access denied"

I just had a quick look into the aforementioned thread on stackoverflow.
The answers are a bit off the track.  The problem here is that you mix
Windows and Cygwin tools in a directory with weird default permissions
which don't translate nicely to POSIX permissions.

Here's what happens:

- cmd's echo will create the file with default inherited Windows
  permission bits.  These permission bits don't make a lot of sense
  from a POSIX point of view.  That's where the ---------+ permissions
  come from.  That doesn't mean that you have no permissions!  Note
  the + at the end which means, there's an ACL with additional
  permissions attached to the file.  Use getfacl(Cygwin) or cacls(Windows)
  to print the extra ACEs.

- Now you call Cygwin's sed to do in-place editing.  The in-place
  editing works like this:

  - Create temporary file.
  - write output to temporary file.
  - Remove original file.
  - Move temp file to original file
  - Restore permissions from original file *in a POSIXy way*.  I don't
    know exactly how sed does that.

The problem here are the default permissions on the directory you're
calling CMD's echo in the first place.  If you don't want to change them,
make sure that Cygwin ignores the permissions entirely and only fakes
POSIX permissions on that directory.  That's what the "noacl" mount
option is for: http://cygwin.com/cygwin-ug-net/using.html#mount-table


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019