Function inArchivePath

Synopsis

#include <include/fsitem.hpp>

wstring inArchivePath() const

Description

NOTE: inArchivePath() returns the path that should be used inside the archive when compressing the item, i.e. the path relative to the 'root' of the archive. This is needed in order to behave like 7-zip and retaining the directory structure when creating new archives.

In particular, 7-zip behaves differently according to the kind of paths that are passed to it:

  • absolute paths (e.g. "C:\foo\bar\test.txt"): the file is compressed without any directory structure (e.g. "test.txt"), unless it was inside a directory passed by the user and scanned by FSIndexer: in this case only the directory structure is retained.
  • relative paths containing current dir or outside references (e.g. containing a "./" or "../" substring, like in "../foo/bar/test.txt"): same as absolute paths (e.g. "test.txt").
  • relative paths (e.g. "foo/bar/test.txt"): the file is compressed retaining the directory structure (e.g. "foo/bar/test.txt" in both example cases).

If the mInArchivePath is already given (i.e. the user wants a custom mapping of files), this one is returned.

Source

Lines 131-155 in src/fsitem.cpp. Line 55 in include/fsitem.hpp.

wstring FSItem::inArchivePath() const {
    using namespace fsutil;

    if ( !mInArchivePath.empty() ) {
        return mInArchivePath;
    }

    if ( !isRelativePath( mPath ) || contains_dot_references( mPath ) ) {
        // Note: in this case if the file was found while searching in a directory passed by the user, we need to retain
        // the interal structure of that folder (mSearchPath), otherwise we use only the file name.
        return mSearchPath.empty() ? name() : mSearchPath + L"\\" + name();
    }

    if ( mPath == L"." || mPath == L".." ) {
        return L"";
    }

    //path is relative and without ./ or ../ => e.g. foo/bar/test.txt

    if ( !mSearchPath.empty() ) {
        // The item was found while indexing a directory
        return mSearchPath + L"\\" + name();
    }
    return mPath;
}





Add Discussion as Guest

Log in