mirror of https://github.com/apache/lucene.git
LUCENE-6051: don't use trappy Iterable<Path> in helper functions
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1637278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
218fc55d70
commit
497e64e2b9
|
@ -37,6 +37,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.StandardOpenOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -215,7 +216,7 @@ public final class IOUtils {
|
|||
* <p>
|
||||
* Some of the files may be null, if so they are ignored.
|
||||
*/
|
||||
public static void deleteFilesIgnoringExceptions(Iterable<? extends Path> files) {
|
||||
public static void deleteFilesIgnoringExceptions(Collection<? extends Path> files) {
|
||||
for (Path name : files) {
|
||||
if (name != null) {
|
||||
try {
|
||||
|
@ -249,7 +250,7 @@ public final class IOUtils {
|
|||
*
|
||||
* @param files files to delete
|
||||
*/
|
||||
public static void deleteFilesIfExist(Iterable<? extends Path> files) throws IOException {
|
||||
public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException {
|
||||
Throwable th = null;
|
||||
|
||||
for (Path file : files) {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package org.apache.lucene.util;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/** Simple test methods for IOUtils */
|
||||
public class TestIOUtils extends LuceneTestCase {
|
||||
|
||||
public void testDeleteFileIgnoringExceptions() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
Files.createFile(file1);
|
||||
IOUtils.deleteFilesIgnoringExceptions(file1);
|
||||
assertFalse(Files.exists(file1));
|
||||
// actually deletes
|
||||
}
|
||||
|
||||
public void testDontDeleteFileIgnoringExceptions() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
IOUtils.deleteFilesIgnoringExceptions(file1);
|
||||
// no exception
|
||||
}
|
||||
|
||||
public void testDeleteTwoFilesIgnoringExceptions() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
Path file2 = dir.resolve("file2");
|
||||
// only create file2
|
||||
Files.createFile(file2);
|
||||
IOUtils.deleteFilesIgnoringExceptions(file1, file2);
|
||||
assertFalse(Files.exists(file2));
|
||||
// no exception
|
||||
// actually deletes file2
|
||||
}
|
||||
|
||||
public void testDeleteFileIfExists() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
Files.createFile(file1);
|
||||
IOUtils.deleteFilesIfExist(file1);
|
||||
assertFalse(Files.exists(file1));
|
||||
// actually deletes
|
||||
}
|
||||
|
||||
public void testDontDeleteDoesntExist() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
IOUtils.deleteFilesIfExist(file1);
|
||||
// no exception
|
||||
}
|
||||
|
||||
public void testDeleteTwoFilesIfExist() throws Exception {
|
||||
Path dir = createTempDir();
|
||||
Path file1 = dir.resolve("file1");
|
||||
Path file2 = dir.resolve("file2");
|
||||
// only create file2
|
||||
Files.createFile(file2);
|
||||
IOUtils.deleteFilesIfExist(file1, file2);
|
||||
assertFalse(Files.exists(file2));
|
||||
// no exception
|
||||
// actually deletes file2
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue