Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5934 closed defect (fixed)

Renaming of directories using the memory filesystem driver

Reported by: dsogari Owned by: warmerdam
Priority: normal Milestone: 2.0.0
Component: default Version: svn-trunk
Severity: minor Keywords: VSIRename; memory

Description (last modified by dsogari)


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


        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;
                oFileList[osNewFullPath] = it->second;
                it->second->osFilename = osNewFullPath;
            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.


Change History (3)

comment:1 Changed 6 years ago by dsogari

Description: modified (diff)

comment:2 Changed 6 years ago by Even Rouault

Milestone: 2.0
Resolution: fixed
Status: newclosed

trunk r28976 "Make Rename() on a /vsimem/ directory also rename filenames under that directory (patch by dsogari + added test by me, #5934)"

comment:3 Changed 6 years ago by Even Rouault


Milestone renamed

Note: See TracTickets for help on using tickets.