From 9cf7a628c2ff178b2fa236d2c0a41ca9be315036 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 25 Oct 2011 15:32:11 -0400 Subject: [PATCH] Windows: Do not EEXIST exact match during rename AFS Rename operations on the file server will delete a target file if it exists. Do not prevent renames because an exact match of the target name exists in the target directory. Change-Id: I680f8886575a9276a8df05965d14bbe7f24fba5d Reviewed-on: http://gerrit.openafs.org/5731 Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsd/cm_vnodeops.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/WINNT/afsd/cm_vnodeops.c b/src/WINNT/afsd/cm_vnodeops.c index aff45a81e..605ff3189 100644 --- a/src/WINNT/afsd/cm_vnodeops.c +++ b/src/WINNT/afsd/cm_vnodeops.c @@ -3586,21 +3586,28 @@ long cm_Rename(cm_scache_t *oldDscp, fschar_t *oldNamep, clientchar_t *cOldNamep goto done; } - code = cm_Lookup(newDscp, cNewNamep, CM_FLAG_CASEFOLD, userp, reqp, &newScp); - if (code == 0) { - /* found a matching object with the new name */ - if (cm_FidCmp(&oldScp->fid, &newScp->fid)) { - /* and they don't match so return an error */ - osi_Log2(afsd_logp, "cm_Rename newDscp 0x%p cNewName %S new name already exists", - newDscp, osi_LogSaveStringW(afsd_logp, cNewNamep)); + /* Case sensitive lookup. If this succeeds we are done. */ + code = cm_Lookup(newDscp, cNewNamep, 0, userp, reqp, &newScp); + if (code) { + /* + * Case insensitive lookup. If this succeeds, it could have found the + * same file with a name that differs only by case or it could be a + * different file entirely. + */ + code = cm_Lookup(newDscp, cNewNamep, CM_FLAG_CASEFOLD, userp, reqp, &newScp); + if (code == 0) { + /* found a matching object with the new name */ + if (cm_FidCmp(&oldScp->fid, &newScp->fid)) { + /* and they don't match so return an error */ + osi_Log2(afsd_logp, "cm_Rename newDscp 0x%p cNewName %S new name already exists", + newDscp, osi_LogSaveStringW(afsd_logp, cNewNamep)); + code = CM_ERROR_EXISTS; + } + cm_ReleaseSCache(newScp); + newScp = NULL; + } else if (code == CM_ERROR_AMBIGUOUS_FILENAME) { code = CM_ERROR_EXISTS; } - cm_ReleaseSCache(newScp); - newScp = NULL; - } else if (code == CM_ERROR_AMBIGUOUS_FILENAME) { - code = CM_ERROR_EXISTS; - } else { - code = 0; } /* Check for RO volume */ -- 2.39.5