Ticket #2641: vfs_DELETED_folders.patch

File vfs_DELETED_folders.patch, 3.6 KB (added by leper, 5 years ago)
  • source/lib/file/vfs/vfs_populate.cpp

     
    1 /* Copyright (c) 2013 Wildfire Games
     1/* Copyright (c) 2014 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    7878        if(name.Extension() == L".DELETED")
    7979        {
    8080            m_directory->RemoveFile(name.Basename());
     81            m_directory->RemoveSubdirectory(name.Basename());
    8182            if(!(m_realDirectory->Flags() & VFS_MOUNT_KEEP_DELETED))
    8283                return;
    8384        }
     
    100101        if(name.Extension() == L".DELETED")
    101102        {
    102103            directory->RemoveFile(name.Basename());
     104            // Note: .DELETED files should appear before any files in the
     105            // subfolder. Archives that do not follow this should be considered
     106            // broken.
     107            directory->RemoveSubdirectory(name.Basename());
    103108            if(!(this_->m_realDirectory->Flags() & VFS_MOUNT_KEEP_DELETED))
    104109                return;
    105110        }
  • source/lib/file/vfs/vfs_tree.cpp

     
    122122    return &it->second;
    123123}
    124124
     125void VfsDirectory::RemoveSubdirectory(const VfsPath& name)
     126{
     127    VfsSubdirectories::iterator it = m_subdirectories.find(name.string());
     128    if(it == m_subdirectories.end())
     129        return;
     130    it->second.Clear();
     131    m_subdirectories.erase(it);
     132}
    125133
    126134VfsDirectory* VfsDirectory::GetSubdirectory(const VfsPath& name)
    127135{
  • source/lib/file/vfs/vfs_tree.h

     
    1 /* Copyright (c) 2010 Wildfire Games
     1/* Copyright (c) 2014 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    106106    VfsFile* GetFile(const VfsPath& name);
    107107
    108108    /**
     109     * remove the given subdirectory (and all files and directories in it)
     110     * from the virtual directory. no effect if the subdirectory does not exist.
     111     * CAUTION: Invalidates all previously returned pointers of this subdirectory
     112     *          and everything contained in it.
     113     **/
     114    void RemoveSubdirectory(const VfsPath& name);
     115
     116    /**
    109117     * @return subdirectory with the given name.
    110118     * (note: non-const to allow changes to the subdirectory)
    111119     **/
  • source/ps/ArchiveBuilder.cpp

     
    8282
    8383    CXeromyces xero;
    8484
     85    // Add .DELETED files first, so that we can safely remove folders,
     86    // without having to worry about removing files we add.
     87    for (size_t i = 0; i < m_Files.size(); ++i)
     88    {
     89        const VfsPath path = m_Files[i];
     90        if (path.Extension() != L".DELETED")
     91            continue;
     92
     93        Status ret;
     94        OsPath realPath;
     95        ret = m_VFS->GetRealPath(path, realPath);
     96        ENSURE(ret == INFO::OK);
     97        debug_printf(L"Adding %ls\n", realPath.string().c_str());
     98        writer->AddFile(realPath, path);
     99    }
     100
    85101    for (size_t i = 0; i < m_Files.size(); ++i)
    86102    {
    87103        Status ret;
    88104
    89105        const VfsPath path = m_Files[i];
     106        // We already added those, adding them twice might remove files we want to keep.
     107        if (path.Extension() == L".DELETED")
     108            continue;
     109
    90110        OsPath realPath;
    91111        ret = m_VFS->GetRealPath(path, realPath);
    92112        ENSURE(ret == INFO::OK);