public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* sed 4.2.1-1 locks files on windows
@ 2012-02-21 10:58 cygwin.com
  2012-02-21 11:45 ` Corinna Vinschen
  0 siblings, 1 reply; 3+ messages in thread
From: cygwin.com @ 2012-02-21 10:58 UTC (permalink / raw)
  To: cygwin

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"

-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren: http://www.gmx.net/de/go/freephone/

--
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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sed 4.2.1-1 locks files on windows
  2012-02-21 10:58 sed 4.2.1-1 locks files on windows cygwin.com
@ 2012-02-21 11:45 ` Corinna Vinschen
  2012-02-22  2:12   ` L Anderson
  0 siblings, 1 reply; 3+ messages in thread
From: Corinna Vinschen @ 2012-02-21 11:45 UTC (permalink / raw)
  To: cygwin

On Feb 21 11:58, cygwin.com@munub.e4ward.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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sed 4.2.1-1 locks files on windows
  2012-02-21 11:45 ` Corinna Vinschen
@ 2012-02-22  2:12   ` L Anderson
  0 siblings, 0 replies; 3+ messages in thread
From: L Anderson @ 2012-02-22  2:12 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen wrote:
> On Feb 21 11:58, cygwin.com@munub.e4ward.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.

NB: On Win 7 one is informed-- "NOTE: Cacls is now deprecated, please 
use Icacls."

Regards,

LA

--
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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-22  2:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 10:58 sed 4.2.1-1 locks files on windows cygwin.com
2012-02-21 11:45 ` Corinna Vinschen
2012-02-22  2:12   ` L Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).