Changed deleteInDirectoryApartFrom to take variadic type.

This commit is contained in:
Winston Li 2014-11-17 13:08:29 +00:00
parent 3bbef6f066
commit 555f4e1674
2 changed files with 7 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotAttachm
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile; import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
import uk.ac.ic.wlgitbridge.writelatex.filestore.RepositoryFile; import uk.ac.ic.wlgitbridge.writelatex.filestore.RepositoryFile;
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore; import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot; import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
import java.io.File; import java.io.File;
@ -59,8 +60,10 @@ public class WLDirectoryNode {
public WLDirectoryNode createFromRawDirectoryContents(RawDirectoryContents rawDirectoryContents, File attachmentDirectory) throws IOException, FailedConnectionException { public WLDirectoryNode createFromRawDirectoryContents(RawDirectoryContents rawDirectoryContents, File attachmentDirectory) throws IOException, FailedConnectionException {
Map<String, FileNode> candidateFileNodeTable = new HashMap<String, FileNode>(); Map<String, FileNode> candidateFileNodeTable = new HashMap<String, FileNode>();
File projectAttDirectory = new File(attachmentDirectory, projectName);
WLFileStore.deleteInDirectory(projectAttDirectory);
for (Entry<String, byte[]> fileContents : rawDirectoryContents.getFileContentsTable().entrySet()) { for (Entry<String, byte[]> fileContents : rawDirectoryContents.getFileContentsTable().entrySet()) {
BlobNode blobNode = new BlobNode(new RepositoryFile(fileContents), fileNodeTable, new File(attachmentDirectory, projectName)); BlobNode blobNode = new BlobNode(new RepositoryFile(fileContents), fileNodeTable, projectAttDirectory);
candidateFileNodeTable.put(blobNode.getFilePath(), blobNode); candidateFileNodeTable.put(blobNode.getFilePath(), blobNode);
} }
return new WLDirectoryNode(projectName, candidateFileNodeTable, return new WLDirectoryNode(projectName, candidateFileNodeTable,

View file

@ -41,9 +41,10 @@ public class WLFileStore {
} }
} }
public static void deleteInDirectoryApartFrom(File directory, String apartFrom) { public static void deleteInDirectoryApartFrom(File directory, String... apartFrom) {
Set<String> excluded = new HashSet<String>(Arrays.asList(apartFrom));
for (File file : directory.listFiles()) { for (File file : directory.listFiles()) {
if (!file.getName().equals(apartFrom)) { if (!excluded.contains(file.getName())) {
if (file.isDirectory()) { if (file.isDirectory()) {
deleteInDirectory(file); deleteInDirectory(file);
} }