Opened 9 years ago
Last modified 9 years ago
#5934 closed defect
Renaming of directories using the memory filesystem driver — at Version 1
Reported by: | dsogari | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 2.0.0 |
Component: | default | Version: | svn-trunk |
Severity: | minor | Keywords: | VSIRename; memory |
Cc: |
Description (last modified by )
Hi,
I spot an issue with the VSIRename function using the memory filesystem driver. The problem is that it does not properly handle renaming of directories. I know not whether this feature was officially supported. However, I took the liberty of writing a replacement code, which seems to work, and I thought of sharing it. The following is what I came up with.
in gdal/port/cpl_vsi_mem.cpp [my local copy is in r28752]
method VSIMemFilesystemHandler::Rename
lines 737 through 744:
VSIMemFile* poFile = oFileList[osOldPath]; oFileList.erase( oFileList.find(osOldPath) ); Unlink_unlocked(osNewPath); oFileList[osNewPath] = poFile; poFile->osFilename = osNewPath;
replace by:
std::map<CPLString,VSIMemFile*>::iterator it = oFileList.find(osOldPath); while (it != oFileList.end() && it->first.ifind(osOldPath) == 0) { const CPLString osRemainder = it->first.substr(osOldPath.size()); if (osRemainder.empty() || osRemainder[0] == '/') { const CPLString osNewFullPath = osNewPath + osRemainder; Unlink_unlocked(osNewFullPath); oFileList[osNewFullPath] = it->second; it->second->osFilename = osNewFullPath; oFileList.erase(it++); } else ++it; }
I do not claim to say the code is correct. However, it is what I could devise to solve my problem under the circumstances (time, mostly). And solve it did. Please reply with corrections and/or improvements.
Regards.