Search in sources :

Example 16 with ForbiddenSymlinkException

use of org.opengrok.indexer.util.ForbiddenSymlinkException in project OpenGrok by OpenGrok.

the class FileHistoryCache method createDirectoriesForFiles.

private void createDirectoriesForFiles(Set<String> files, Repository repository, String label) throws HistoryException {
    // The directories for the files have to be created before
    // the actual files otherwise storeFile() might be racing for
    // mkdirs() if there are multiple files from single directory
    // handled in parallel.
    Statistics elapsed = new Statistics();
    LOGGER.log(Level.FINE, "Starting directory creation for {0} ({1}): {2} directories", new Object[] { repository, label, files.size() });
    for (final String file : files) {
        File cache;
        try {
            cache = getCachedFile(new File(env.getSourceRootPath() + file));
        } catch (ForbiddenSymlinkException ex) {
            LOGGER.log(Level.FINER, ex.getMessage());
            continue;
        }
        File dir = cache.getParentFile();
        if (!dir.isDirectory() && !dir.mkdirs()) {
            LOGGER.log(Level.WARNING, "Unable to create cache directory ''{0}''.", dir);
        }
    }
    elapsed.report(LOGGER, String.format("Done creating directories for %s (%s)", repository, label));
}
Also used : ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) Statistics(org.opengrok.indexer.util.Statistics) File(java.io.File)

Example 17 with ForbiddenSymlinkException

use of org.opengrok.indexer.util.ForbiddenSymlinkException in project OpenGrok by OpenGrok.

the class FileHistoryCache method storeFile.

/**
 * Store history object (encoded as XML and compressed with gzip) in a file.
 *
 * @param histNew history object to store
 * @param file file to store the history object into
 * @param repo repository for the file
 * @param mergeHistory whether to merge the history with existing or
 *                     store the histNew as is
 */
private void storeFile(History histNew, File file, Repository repo, boolean mergeHistory) throws HistoryException {
    File cacheFile;
    try {
        cacheFile = getCachedFile(file);
    } catch (ForbiddenSymlinkException e) {
        LOGGER.log(Level.FINER, e.getMessage());
        return;
    }
    History history = histNew;
    File dir = cacheFile.getParentFile();
    // calling isDirectory twice to prevent a race condition
    if (!dir.isDirectory() && !dir.mkdirs() && !dir.isDirectory()) {
        throw new HistoryException("Unable to create cache directory '" + dir + "'.");
    }
    if (mergeHistory && cacheFile.exists()) {
        history = mergeOldAndNewHistory(cacheFile, histNew, repo);
    }
    // In such case store at least new history as the best effort.
    if (history == null) {
        LOGGER.log(Level.WARNING, "history cache for file ''{0}'' truncated to new history", file);
        history = histNew;
    }
    writeHistoryToFile(dir, history, cacheFile);
}
Also used : ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) File(java.io.File)

Aggregations

ForbiddenSymlinkException (org.opengrok.indexer.util.ForbiddenSymlinkException)17 File (java.io.File)14 IOException (java.io.IOException)8 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)7 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 InvalidPathException (java.nio.file.InvalidPathException)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 TreeSet (java.util.TreeSet)2 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)2 Statistics (org.opengrok.indexer.util.Statistics)2 Inject (jakarta.inject.Inject)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 Consumes (jakarta.ws.rs.Consumes)1 DELETE (jakarta.ws.rs.DELETE)1 GET (jakarta.ws.rs.GET)1