private void PurgeUnexpectedFiles(DefaultDiskStorage storage) { storage.PurgeUnexpectedResources(); }
public void TestPurgeUnexpectedFiles() { DefaultDiskStorage storage = GetStorageSupplier(1).Get(); string resourceId = "file1"; byte[] CONTENT = Encoding.UTF8.GetBytes("content"); FileInfo file = WriteFileToStorage(storage, resourceId, CONTENT); // Check file exists Assert.IsTrue(file.Exists); CollectionAssert.AreEqual(CONTENT, Files.ToByteArray(file)); FileInfo unexpectedFile1 = new FileInfo( Path.Combine(_directory.FullName, "unexpected-file-1")); FileInfo unexpectedFile2 = new FileInfo( Path.Combine(_directory.FullName, "unexpected-file-2")); Assert.IsTrue(unexpectedFile1.CreateEmpty()); Assert.IsTrue(unexpectedFile2.CreateEmpty()); DirectoryInfo unexpectedDir1 = new DirectoryInfo( Path.Combine(_directory.FullName, "unexpected-dir-1")); DirectoryInfo unexpectedDir2 = new DirectoryInfo( Path.Combine(_directory.FullName, "unexpected-dir-2")); Assert.IsTrue(unexpectedDir1.CreateEmpty()); Assert.IsTrue(unexpectedDir2.CreateEmpty()); FileInfo unexpectedSubfile1 = new FileInfo( Path.Combine(unexpectedDir2.FullName, "unexpected-sub-file-1")); Assert.IsTrue(unexpectedSubfile1.CreateEmpty()); Assert.AreEqual(5, _directory.ListFiles().Length); // 4 unexpected (files+dirs) + ver. dir Assert.AreEqual(1, unexpectedDir2.ListFiles().Length); Assert.AreEqual(0, unexpectedDir1.ListFiles().Length); FileInfo unexpectedFileInShard = new FileInfo( Path.Combine(file.GetParent().FullName, "unexpected-in-shard")); Assert.IsTrue(unexpectedFileInShard.CreateEmpty()); storage.PurgeUnexpectedResources(); unexpectedFile1.Refresh(); unexpectedFile2.Refresh(); unexpectedSubfile1.Refresh(); unexpectedDir1.Refresh(); unexpectedDir2.Refresh(); Assert.IsFalse(unexpectedFile1.Exists); Assert.IsFalse(unexpectedFile2.Exists); Assert.IsFalse(unexpectedSubfile1.Exists); Assert.IsFalse(unexpectedDir1.Exists); Assert.IsFalse(unexpectedDir2.Exists); // Check file still exists Assert.IsTrue(file.Exists); // Check unexpected sibling is gone Assert.IsFalse(unexpectedFileInShard.Exists); // Check the only thing in root is the version directory Assert.AreEqual(1, _directory.ListFiles().Length); // just the version directory }