mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- The Unix-like rename() now removes the target file even if that
file has been protected from deletion. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14920 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
- The Unix-like rename() now removes the target file even if that
|
||||
file has been protected from deletion.
|
||||
|
||||
|
||||
c.lib 1.191 (9.4.2005)
|
||||
|
||||
- The name of the public record locking semaphore has to be preallocated
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: stdio_rename.c,v 1.4 2005-02-28 10:07:31 obarthel Exp $
|
||||
* $Id: stdio_rename.c,v 1.5 2005-04-20 12:06:00 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -63,6 +63,8 @@ rename(const char *oldname,const char *newname)
|
||||
if(__check_abort_enabled)
|
||||
__check_abort();
|
||||
|
||||
PROFILE_OFF();
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(oldname == NULL || newname == NULL)
|
||||
@ -96,9 +98,7 @@ rename(const char *oldname,const char *newname)
|
||||
|
||||
D(("renaming '%s' to '%s'",oldname,newname));
|
||||
|
||||
PROFILE_OFF();
|
||||
status = Rename((STRPTR)oldname,(STRPTR)newname);
|
||||
PROFILE_ON();
|
||||
|
||||
if(status == DOSFALSE)
|
||||
{
|
||||
@ -106,13 +106,14 @@ rename(const char *oldname,const char *newname)
|
||||
|
||||
#if defined(UNIX_PATH_SEMANTICS)
|
||||
{
|
||||
BOOL renamed;
|
||||
LONG error;
|
||||
|
||||
if(IoErr() != ERROR_OBJECT_EXISTS)
|
||||
error = IoErr();
|
||||
if(error != ERROR_OBJECT_EXISTS)
|
||||
{
|
||||
SHOWMSG("that was some other error");
|
||||
|
||||
__set_errno(__translate_io_error_to_errno(IoErr()));
|
||||
__set_errno(__translate_io_error_to_errno(error));
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -120,11 +121,35 @@ rename(const char *oldname,const char *newname)
|
||||
|
||||
/* ZZZ there should be a safer solution for this */
|
||||
|
||||
PROFILE_OFF();
|
||||
renamed = (BOOL)(DeleteFile((STRPTR)newname) && Rename((STRPTR)oldname,(STRPTR)newname));
|
||||
PROFILE_ON();
|
||||
if(CANNOT DeleteFile((STRPTR)newname))
|
||||
{
|
||||
error = IoErr();
|
||||
if(error != ERROR_DELETE_PROTECTED && error != ERROR_OBJECT_NOT_FOUND)
|
||||
{
|
||||
SHOWMS("couldn't delete the file");
|
||||
|
||||
if(NOT renamed)
|
||||
__set_errno(__translate_io_error_to_errno(error));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(CANNOT SetProtection((STRPTR)newname,0))
|
||||
{
|
||||
SHOWMS("couldn't reset the protection");
|
||||
|
||||
__set_errno(__translate_io_error_to_errno(IoErr()));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(CANNOT DeleteFile((STRPTR)newname))
|
||||
{
|
||||
SHOWMS("couldn't delete the file again");
|
||||
|
||||
__set_errno(__translate_io_error_to_errno(IoErr()));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if(CANNOT Rename((STRPTR)oldname,(STRPTR)newname))
|
||||
{
|
||||
SHOWMSG("that didn't work");
|
||||
|
||||
@ -144,6 +169,8 @@ rename(const char *oldname,const char *newname)
|
||||
|
||||
out:
|
||||
|
||||
PROFILE_ON();
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user