예제 #1
0
void FileListerUnix::recursiveAddFiles2(std::vector<std::string> &relative,
                                        std::vector<std::string> &absolute,
                                        const std::string &path)
{
    std::ostringstream oss;
    oss << path;
    if (path.length() > 0 && path[path.length()-1] == '/')
        oss << "*";

    glob_t glob_results;
    glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results);
    for (unsigned int i = 0; i < glob_results.gl_pathc; i++)
    {
        const std::string filename = glob_results.gl_pathv[i];
        if (filename == "." || filename == ".." || filename.length() == 0)
            continue;

        if (filename[filename.length()-1] != '/')
        {
            // File
#ifdef PATH_MAX
            char fname[PATH_MAX];
            if (realpath(filename.c_str(), fname) == NULL)
#else
            char *fname;
            if ((fname = realpath(filename.c_str(), NULL)) == NULL)
#endif
            {
                continue;
            }

            // Does absolute path exist? then bail out
            if (std::find(absolute.begin(), absolute.end(), std::string(fname)) != absolute.end())
            {
#ifndef PATH_MAX
                free(fname);
#endif
                continue;
            }

            if (Path::sameFileName(path,filename) || FileLister::acceptFile(filename))
            {
                relative.push_back(filename);
                absolute.push_back(fname);
            }

#ifndef PATH_MAX
            free(fname);
#endif
        }
        else
        {
            // Directory
            recursiveAddFiles2(relative, absolute, filename);
        }
    }
    globfree(&glob_results);
}
예제 #2
0
void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
                                    std::map<std::string, std::size_t> &files,
                                    const std::string &path,
                                    const std::set<std::string> &extra)
{
    std::ostringstream oss;
    oss << path;
    if (path.length() > 0 && path[path.length()-1] == '/')
        oss << "*";

    glob_t glob_results;
    glob(oss.str().c_str(), GLOB_MARK, 0, &glob_results);
    for (unsigned int i = 0; i < glob_results.gl_pathc; i++) {
        const std::string filename = glob_results.gl_pathv[i];
        if (filename == "." || filename == ".." || filename.length() == 0)
            continue;

        // Determine absolute path. Empty filename if path does not exist
        const std::string absolute_path = getAbsolutePath(filename);
        if (absolute_path.empty())
            continue;

        // Did we already process this entry?
        if (seen_paths.find(absolute_path) != seen_paths.end())
            continue;

        if (filename[filename.length()-1] != '/') {
            // File

            if (Path::sameFileName(path,filename) || Path::acceptFile(filename, extra)) {
                seen_paths.insert(absolute_path);

                struct stat sb;
                if (stat(absolute_path.c_str(), &sb) == 0) {
                    // Limitation: file sizes are assumed to fit in a 'size_t'
                    files[filename] = static_cast<std::size_t>(sb.st_size);
                } else
                    files[filename] = 0;
            }
        } else {
            // Directory

            seen_paths.insert(absolute_path);
            recursiveAddFiles2(seen_paths, files, filename, extra);
        }
    }
    globfree(&glob_results);
}
예제 #3
0
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra)
{
    std::set<std::string> seen_paths;
    recursiveAddFiles2(seen_paths, files, path, extra);
}
예제 #4
0
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const Library * library)
{
    std::set<std::string> seen_paths;
    recursiveAddFiles2(seen_paths, files, path, library);
}
예제 #5
0
void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, std::map<std::string, long> &filesizes, const std::string &path)
{
    std::set<std::string> seen_paths;
    recursiveAddFiles2(filenames, seen_paths, filesizes, path);
}
예제 #6
0
void FileListerUnix::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path)
{
    std::vector<std::string> abs;
    recursiveAddFiles2(filenames, abs, path);
}