diff options
Diffstat (limited to 'dep/mysqllite/mysys/my_delete.c')
-rw-r--r-- | dep/mysqllite/mysys/my_delete.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/dep/mysqllite/mysys/my_delete.c b/dep/mysqllite/mysys/my_delete.c index 22425ed95fd..4a23fedb5ab 100644 --- a/dep/mysqllite/mysys/my_delete.c +++ b/dep/mysqllite/mysys/my_delete.c @@ -36,8 +36,8 @@ int my_delete(const char *name, myf MyFlags) DBUG_RETURN(err); } /* my_delete */ -#if defined(__WIN__) && defined(__NT__) -/* +#if defined(__WIN__) +/** Delete file which is possibly not closed. This function is intended to be used exclusively as a temporal solution @@ -53,6 +53,20 @@ int my_delete(const char *name, myf MyFlags) renamed to <name>.<num>.deleted where <name> - the initial name of the file, <num> - a hexadecimal number chosen to make the temporal name to be unique. + + @param the name of the being deleted file + @param the flags instructing how to react on an error internally in + the function + + @note The per-thread @c my_errno holds additional info for a caller to + decide how critical the error can be. + + @retval + 0 ok + @retval + 1 error + + */ int nt_share_delete(const char *name, myf MyFlags) { @@ -63,6 +77,7 @@ int nt_share_delete(const char *name, myf MyFlags) for (cnt= GetTickCount(); cnt; cnt--) { + errno= 0; sprintf(buf, "%s.%08X.deleted", name, cnt); if (MoveFile(name, buf)) break; @@ -79,14 +94,32 @@ int nt_share_delete(const char *name, myf MyFlags) break; } - if (DeleteFile(buf)) - DBUG_RETURN(0); + if (errno == ERROR_FILE_NOT_FOUND) + { + my_errno= ENOENT; // marking, that `name' doesn't exist + } + else if (errno == 0) + { + if (DeleteFile(buf)) + DBUG_RETURN(0); + /* + The below is more complicated than necessary. For some reason, the + assignment to my_errno clears the error number, which is retrieved + by GetLastError() (VC2005EE). Assigning to errno first, allows to + retrieve the correct value. + */ + errno= GetLastError(); + if (errno == 0) + my_errno= ENOENT; // marking, that `buf' doesn't exist + else + my_errno= errno; + } + else + my_errno= errno; - my_errno= GetLastError(); if (MyFlags & (MY_FAE+MY_WME)) my_error(EE_DELETE, MYF(ME_BELL + ME_WAITTANG + (MyFlags & ME_NOINPUT)), - name, my_errno); - + name, my_errno); DBUG_RETURN(-1); } #endif |