Ticket #8904: archive-prefix.patch

File archive-prefix.patch, 3.4 KB (added by peres, 16 years ago)

The FSDirectory prefix patch.

  • archive.cpp

     
    7171 */
    7272class FSDirectoryMember : public ArchiveMember {
    7373        FSNode  _node;
    74  
     74
    7575public:
    7676        FSDirectoryMember(FSNode &node) : _node(node) {
    7777        }
     
    9696
    9797FSDirectory::FSDirectory(const FSNode &node, int depth)
    9898  : _node(node), _cached(false), _depth(depth) {
     99
     100        setPrefix(String::emptyString);
    99101}
    100102
     103FSDirectory::FSDirectory(const String &prefix, const FSNode &node, int depth)
     104  : _node(node), _cached(false), _depth(depth) {
     105
     106        setPrefix(prefix);
     107}
     108
    101109FSDirectory::FSDirectory(const String &name, int depth)
    102110  : _node(name), _cached(false), _depth(depth) {
     111
     112        setPrefix(String::emptyString);
    103113}
    104114
     115FSDirectory::FSDirectory(const String &prefix, const String &name, int depth)
     116  : _node(name), _cached(false), _depth(depth) {
     117
     118        setPrefix(prefix);
     119}
     120
    105121FSDirectory::~FSDirectory() {
    106122}
    107123
     124void FSDirectory::setPrefix(const String &prefix) {
     125        _prefix = prefix;
     126
     127        if (!_prefix.empty() && !_prefix.hasSuffix("/")) {
     128                _prefix += "/";
     129        }
     130}
     131
    108132FSNode FSDirectory::getFSNode() const {
    109133        return _node;
    110134}
     
    113137        // make caching as lazy as possible
    114138        if (!name.empty()) {
    115139                if (!_cached) {
    116                         cacheDirectoryRecursive(_node, _depth, "");
     140                        cacheDirectoryRecursive(_node, _depth, _prefix);
    117141                        _cached = true;
    118142                }
    119143
     
    157181}
    158182
    159183FSDirectory *FSDirectory::getSubDirectory(const String &name, int depth) {
     184        return getSubDirectory(String::emptyString, name, depth);
     185}
     186
     187FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &name, int depth) {
    160188        if (name.empty() || !_node.isDirectory()) {
    161189                return 0;
    162190        }
    163191
    164192        FSNode node = lookupCache(_subDirCache, name);
    165         return new FSDirectory(node, depth);
     193        return new FSDirectory(prefix, node, depth);
    166194}
    167195
    168196void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) {
  • archive.h

     
    131131        // Key is stored in lowercase.
    132132        typedef HashMap<String, FSNode, IgnoreCase_Hash, IgnoreCase_EqualTo> NodeCache;
    133133        NodeCache       _fileCache, _subDirCache;
     134        Common::String  _prefix;        // string that is prepended to each cache item key
     135        void setPrefix(const String &prefix);
    134136
    135137        // look for a match
    136138        FSNode lookupCache(NodeCache &cache, const String &name);
     
    146148         * unbound FSDirectory if name is not found on the filesystem or is not a directory.
    147149         */
    148150        FSDirectory(const String &name, int depth = 1);
     151        FSDirectory(const String &prefix, const String &name, int depth = 1);
    149152
    150153        /**
    151154         * Create a FSDirectory representing a tree with the specified depth. Will result in an
    152155         * unbound FSDirectory if node does not exist or is not a directory.
    153156         */
    154157        FSDirectory(const FSNode &node, int depth = 1);
     158        FSDirectory(const String &prefix, const FSNode &node, int depth = 1);
    155159
    156160        virtual ~FSDirectory();
    157161
     
    165169         * @return a new FSDirectory instance
    166170         */
    167171        FSDirectory *getSubDirectory(const String &name, int depth = 1);
     172        FSDirectory *getSubDirectory(const String &prefix, const String &name, int depth = 1);
    168173
    169174        virtual bool hasFile(const String &name);
    170175        virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern);