Skip to content

Commit

Permalink
remove individual history files
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Jul 19, 2017
1 parent 3f6755e commit e31a033
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/org/opensolaris/opengrok/history/FileHistoryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,25 @@ public void clear(Repository repository) {
}
}

@Override
public void clearFile(String path) {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
File historyFile = new File(env.getDataRootFile(),
historyDirName + File.separator + path);
File parent = historyFile.getParentFile();

if (!historyFile.delete() && historyFile.exists()) {
LOGGER.log(Level.WARNING,
"Failed to remove obsolete history cache-file: {0}",
historyFile.getAbsolutePath());
}

if (parent.delete()) {
LOGGER.log(Level.FINE, "Removed empty history cache dir:{0}",
parent.getAbsolutePath());
}
}

@Override
public String getInfo() {
return getClass().getSimpleName();
Expand Down
6 changes: 6 additions & 0 deletions src/org/opensolaris/opengrok/history/HistoryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ Map<String, Date> getLastModifiedTimes(
*/
void clear(Repository repository) throws HistoryException;

/**
* Clear entry for single file from history cache.
* @param file path to the file
*/
void clearFile(String file);

/**
* Get a string with information about the history cache.
*
Expand Down
20 changes: 16 additions & 4 deletions src/org/opensolaris/opengrok/history/HistoryGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ public void createCache(Collection<String> repositories) {
createCacheReal(getReposFromString(repositories));
}

private HistoryCache getHistoryCache() {
HistoryCache cache = historyCache;
if (cache == null) {
cache = new FileHistoryCache();
}

return cache;
}

/**
* Remove history data for a list of repositories
* @param repositories list of repository paths
Expand All @@ -628,10 +637,8 @@ public void createCache(Collection<String> repositories) {
*/
public List<Repository> clearCache(Collection<String> repositories) throws HistoryException {
List<Repository> repos = getReposFromString(repositories);
HistoryCache cache = historyCache;
if (cache == null) {
cache = new FileHistoryCache();
}
HistoryCache cache = getHistoryCache();

for (Repository r : repos) {
try {
cache.clear(r);
Expand All @@ -647,6 +654,11 @@ public List<Repository> clearCache(Collection<String> repositories) throws Histo
return repos;
}

public void clearCacheFile(String path) {
HistoryCache cache = getHistoryCache();
cache.clearFile(path);
}

/**
* Remove history data for a list of repositories and invalidate the list
* of repositories accordingly.
Expand Down
5 changes: 5 additions & 0 deletions src/org/opensolaris/opengrok/index/IndexDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ private void removeXrefFile(String path) {
}
}

private void removeHistoryFile(String path) {
HistoryGuru.getInstance().clearCacheFile(path);
}

/**
* Remove a stale file (uidIter.term().text()) from the index database (and
* the xref file)
Expand All @@ -610,6 +614,7 @@ private void removeFile() throws IOException {
writer.commit();

removeXrefFile(path);
removeHistoryFile(path);

setDirty();
for (IndexChangedListener listener : listeners) {
Expand Down

0 comments on commit e31a033

Please sign in to comment.