1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.rolling.helper;
15
16 import java.io.File;
17 import java.nio.file.FileStore;
18 import java.nio.file.Files;
19 import java.nio.file.Path;
20
21 import ch.qos.logback.core.rolling.RolloverFailure;
22
23
24
25
26
27
28
29 public class FileStoreUtil {
30
31 static final String PATH_CLASS_STR = "java.nio.file.Path";
32 static final String FILES_CLASS_STR = "java.nio.file.Files";
33
34
35
36
37
38
39
40
41
42 static public boolean areOnSameFileStore(File a, File b) throws RolloverFailure {
43 if (!a.exists()) {
44 throw new IllegalArgumentException("File [" + a + "] does not exist.");
45 }
46 if (!b.exists()) {
47 throw new IllegalArgumentException("File [" + b + "] does not exist.");
48 }
49
50
51
52 try {
53 Path pathA = a.toPath();
54 Path pathB = b.toPath();
55
56 FileStore fileStoreA = Files.getFileStore(pathA);
57 FileStore fileStoreB = Files.getFileStore(pathB);
58
59 return fileStoreA.equals(fileStoreB);
60 } catch (Exception e) {
61 throw new RolloverFailure("Failed to check file store equality for [" + a + "] and [" + b + "]", e);
62 }
63 }
64 }