public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* rename() cannot replace the file which is opened with writable access
@ 2017-01-12  0:07 Masamichi Hosoda
  2017-01-12  5:50 ` Andrey Repin
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Masamichi Hosoda @ 2017-01-12  0:07 UTC (permalink / raw)
  To: cygwin; +Cc: trueroad

Hello,

I've found that rename() cannot replace the file
which is opened with writable access on Cygwin.
On Linux, it works.

If I understand correctly, it should work under POSIX.

Here's sample code for reproduce.

```
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#define OLDPATH "oldpath"
#define NEWPATH "newpath"

int main ()
{
  int fd;
  struct flock fl;
  char buff[] = "test";

  /* create oldpath file */
  fd = open (OLDPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
  close (fd);

  /* create newpath file */
  fd = open (NEWPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);

  /* rename *** FAILED on Cygwin *** */
  if (rename (OLDPATH, NEWPATH) < 0)
    perror ("rename");

  close (fd);

  return 0;
}
```

Thanks

--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12  0:07 rename() cannot replace the file which is opened with writable access Masamichi Hosoda
@ 2017-01-12  5:50 ` Andrey Repin
  2017-01-12 14:41   ` Masamichi Hosoda
  2017-01-12 19:06 ` L. A. Walsh
  2017-01-12 21:49 ` Corinna Vinschen
  2 siblings, 1 reply; 10+ messages in thread
From: Andrey Repin @ 2017-01-12  5:50 UTC (permalink / raw)
  To: Masamichi Hosoda, cygwin

Greetings, Masamichi Hosoda!

> I've found that rename() cannot replace the file
> which is opened with writable access on Cygwin.
> On Linux, it works.

It is OS dependent behavior, and vary even on same OS.
Windows may let you rename a file, or may not, depends on how exactly it is
opened.


-- 
With best regards,
Andrey Repin
Thursday, January 12, 2017 08:38:15

Sorry for my terrible english...


--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12  5:50 ` Andrey Repin
@ 2017-01-12 14:41   ` Masamichi Hosoda
  2017-01-12 15:30     ` Nellis, Kenneth (Conduent)
  0 siblings, 1 reply; 10+ messages in thread
From: Masamichi Hosoda @ 2017-01-12 14:41 UTC (permalink / raw)
  To: cygwin, anrdaemon

>> I've found that rename() cannot replace the file
>> which is opened with writable access on Cygwin.
>> On Linux, it works.
> 
> It is OS dependent behavior, and vary even on same OS.
> Windows may let you rename a file, or may not, depends on how exactly it is
> opened.

Thank you for your answer.

If I understand correctly,
POSIX behavior should be able to replace the writable opened file by rename().
But, It does not work on my Cygwin environment.

Is it no problem if Cygwin's behavior is different from POSIX behavior?
If so, we need different application handling for Cygwin and POSIX.

--
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] 10+ messages in thread

* RE: rename() cannot replace the file which is opened with writable access
  2017-01-12 14:41   ` Masamichi Hosoda
@ 2017-01-12 15:30     ` Nellis, Kenneth (Conduent)
  2017-01-12 15:36       ` Corinna Vinschen
  0 siblings, 1 reply; 10+ messages in thread
From: Nellis, Kenneth (Conduent) @ 2017-01-12 15:30 UTC (permalink / raw)
  To: cygwin

From: Masamichi Hosoda
> If I understand correctly,
> POSIX behavior should be able to replace the writable opened file by
> rename().
> But, It does not work on my Cygwin environment.
> 
> Is it no problem if Cygwin's behavior is different from POSIX behavior?
> If so, we need different application handling for Cygwin and POSIX.

I thought it would be informative to respond by referring the OP
to a section of the Cygwin User's Guide or FAQ that mentioned the
limitations of Cygwin, but I could not find it.

--Ken Nellis

--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12 15:30     ` Nellis, Kenneth (Conduent)
@ 2017-01-12 15:36       ` Corinna Vinschen
  2017-01-12 16:38         ` cyg Simple
  0 siblings, 1 reply; 10+ messages in thread
From: Corinna Vinschen @ 2017-01-12 15:36 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 892 bytes --]

On Jan 12 15:30, Nellis, Kenneth (Conduent) wrote:
> From: Masamichi Hosoda
> > If I understand correctly,
> > POSIX behavior should be able to replace the writable opened file by
> > rename().
> > But, It does not work on my Cygwin environment.
> > 
> > Is it no problem if Cygwin's behavior is different from POSIX behavior?
> > If so, we need different application handling for Cygwin and POSIX.
> 
> I thought it would be informative to respond by referring the OP
> to a section of the Cygwin User's Guide or FAQ that mentioned the
> limitations of Cygwin, but I could not find it.

Needs debugging.  Off the top of my head I have no clue why this
doesn't work.  I'm just not near any Windows machine ATM...


Corinna

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12 15:36       ` Corinna Vinschen
@ 2017-01-12 16:38         ` cyg Simple
  0 siblings, 0 replies; 10+ messages in thread
From: cyg Simple @ 2017-01-12 16:38 UTC (permalink / raw)
  To: cygwin

On 1/12/2017 10:36 AM, Corinna Vinschen wrote:
> On Jan 12 15:30, Nellis, Kenneth (Conduent) wrote:
>> From: Masamichi Hosoda
>>> If I understand correctly,
>>> POSIX behavior should be able to replace the writable opened file by
>>> rename().
>>> But, It does not work on my Cygwin environment.
>>>
>>> Is it no problem if Cygwin's behavior is different from POSIX behavior?
>>> If so, we need different application handling for Cygwin and POSIX.
>>
>> I thought it would be informative to respond by referring the OP
>> to a section of the Cygwin User's Guide or FAQ that mentioned the
>> limitations of Cygwin, but I could not find it.
> 
> Needs debugging.  Off the top of my head I have no clue why this
> doesn't work.  I'm just not near any Windows machine ATM...

Possibly BLODA.  In the sample code provided, the rename is trying to
rename the open file to an existing filename that was recently (within
microseconds) created.

-- 
cyg Simple

--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12  0:07 rename() cannot replace the file which is opened with writable access Masamichi Hosoda
  2017-01-12  5:50 ` Andrey Repin
@ 2017-01-12 19:06 ` L. A. Walsh
  2017-01-12 21:49 ` Corinna Vinschen
  2 siblings, 0 replies; 10+ messages in thread
From: L. A. Walsh @ 2017-01-12 19:06 UTC (permalink / raw)
  To: cygwin

Masamichi Hosoda wrote:
> Hello,
>
> I've found that rename() cannot replace the file
> which is opened with writable access on Cygwin.
> On Linux, it works.
>
> If I understand correctly, it should work under POSIX.
>
> Here's sample code for reproduce.
---
> #define OLDPATH "oldpath"
> #define NEWPATH "newpath"
>
> int main () {
>   int fd;
>   struct flock fl;
>   char buff[] = "test";
>   fd = open (OLDPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
>   close (fd);
>   fd = open (NEWPATH, O_CREAT | O_RDWR | O_TRUNC, 0666);
>   if (rename (OLDPATH, NEWPATH) < 0)  perror ("rename");
>   
----
    What are you trying to do by renaming the oldfile
over the top of a still-open-for-write, "newfile".

    Why rename over the top of another file?  What are you trying
to do?  Maybe there is a better way to do it?  ;-). 

--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12  0:07 rename() cannot replace the file which is opened with writable access Masamichi Hosoda
  2017-01-12  5:50 ` Andrey Repin
  2017-01-12 19:06 ` L. A. Walsh
@ 2017-01-12 21:49 ` Corinna Vinschen
  2017-01-14  4:00   ` Masamichi Hosoda
  2 siblings, 1 reply; 10+ messages in thread
From: Corinna Vinschen @ 2017-01-12 21:49 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

On Jan 12 09:07, Masamichi Hosoda wrote:
> Hello,
> 
> I've found that rename() cannot replace the file
> which is opened with writable access on Cygwin.
> On Linux, it works.
> 
> If I understand correctly, it should work under POSIX.
> 
> Here's sample code for reproduce.

Thanks for the testcase.  I applied a patch(*) and will upload a new
developer snapshot for testing to https://cygwin.com/snapshots/
at some point tomorrow.


Corinna

(*) https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=6ed4753

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-12 21:49 ` Corinna Vinschen
@ 2017-01-14  4:00   ` Masamichi Hosoda
  2017-01-14 15:38     ` Corinna Vinschen
  0 siblings, 1 reply; 10+ messages in thread
From: Masamichi Hosoda @ 2017-01-14  4:00 UTC (permalink / raw)
  To: cygwin

>> I've found that rename() cannot replace the file
>> which is opened with writable access on Cygwin.
>> On Linux, it works.
>> 
>> If I understand correctly, it should work under POSIX.
>> 
>> Here's sample code for reproduce.
> 
> Thanks for the testcase.  I applied a patch(*) and will upload a new
> developer snapshot for testing to https://cygwin.com/snapshots/
> at some point tomorrow.
> 
> 
> Corinna
> 
> (*) https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=6ed4753

The snapshot has been fixed the issue.
Thank you.

--
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] 10+ messages in thread

* Re: rename() cannot replace the file which is opened with writable access
  2017-01-14  4:00   ` Masamichi Hosoda
@ 2017-01-14 15:38     ` Corinna Vinschen
  0 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2017-01-14 15:38 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 833 bytes --]

On Jan 14 13:00, Masamichi Hosoda wrote:
> >> I've found that rename() cannot replace the file
> >> which is opened with writable access on Cygwin.
> >> On Linux, it works.
> >> 
> >> If I understand correctly, it should work under POSIX.
> >> 
> >> Here's sample code for reproduce.
> > 
> > Thanks for the testcase.  I applied a patch(*) and will upload a new
> > developer snapshot for testing to https://cygwin.com/snapshots/
> > at some point tomorrow.
> > 
> > 
> > Corinna
> > 
> > (*) https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=6ed4753
> 
> The snapshot has been fixed the issue.
> Thank you.

Thanks for your feedback!


Corinna

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2017-01-14 15:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-12  0:07 rename() cannot replace the file which is opened with writable access Masamichi Hosoda
2017-01-12  5:50 ` Andrey Repin
2017-01-12 14:41   ` Masamichi Hosoda
2017-01-12 15:30     ` Nellis, Kenneth (Conduent)
2017-01-12 15:36       ` Corinna Vinschen
2017-01-12 16:38         ` cyg Simple
2017-01-12 19:06 ` L. A. Walsh
2017-01-12 21:49 ` Corinna Vinschen
2017-01-14  4:00   ` Masamichi Hosoda
2017-01-14 15:38     ` Corinna Vinschen

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