From 555f4e16743059de6c9fa716ddff58412f626114 Mon Sep 17 00:00:00 2001 From: Winston Li Date: Mon, 17 Nov 2014 13:08:29 +0000 Subject: [PATCH] Changed deleteInDirectoryApartFrom to take variadic type. --- .../writelatex/filestore/node/WLDirectoryNode.java | 5 ++++- .../wlgitbridge/writelatex/filestore/store/WLFileStore.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/WLDirectoryNode.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/WLDirectoryNode.java index c7428ed63d..5771bb53b5 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/WLDirectoryNode.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/WLDirectoryNode.java @@ -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.filestore.RepositoryFile; 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 java.io.File; @@ -59,8 +60,10 @@ public class WLDirectoryNode { public WLDirectoryNode createFromRawDirectoryContents(RawDirectoryContents rawDirectoryContents, File attachmentDirectory) throws IOException, FailedConnectionException { Map candidateFileNodeTable = new HashMap(); + File projectAttDirectory = new File(attachmentDirectory, projectName); + WLFileStore.deleteInDirectory(projectAttDirectory); for (Entry 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); } return new WLDirectoryNode(projectName, candidateFileNodeTable, diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java index ac6f2c43f8..783cde97f9 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java @@ -41,9 +41,10 @@ public class WLFileStore { } } - public static void deleteInDirectoryApartFrom(File directory, String apartFrom) { + public static void deleteInDirectoryApartFrom(File directory, String... apartFrom) { + Set excluded = new HashSet(Arrays.asList(apartFrom)); for (File file : directory.listFiles()) { - if (!file.getName().equals(apartFrom)) { + if (!excluded.contains(file.getName())) { if (file.isDirectory()) { deleteInDirectory(file); }