001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.rolling.helper; 015 016import java.io.File; 017import java.nio.file.FileStore; 018import java.nio.file.Files; 019import java.nio.file.Path; 020 021import ch.qos.logback.core.rolling.RolloverFailure; 022 023/** 024 * A utility class using functionality available since JDK 1.7. 025 * 026 * @author ceki 027 * @since 1.0.10 028 */ 029public class FileStoreUtil { 030 031 static final String PATH_CLASS_STR = "java.nio.file.Path"; 032 static final String FILES_CLASS_STR = "java.nio.file.Files"; 033 034 /** 035 * This method assumes that both files a and b exists. 036 * 037 * @param a 038 * @param b 039 * @return 040 * @throws RolloverFailure 041 */ 042 static public boolean areOnSameFileStore(File a, File b) throws RolloverFailure { 043 if (!a.exists()) { 044 throw new IllegalArgumentException("File [" + a + "] does not exist."); 045 } 046 if (!b.exists()) { 047 throw new IllegalArgumentException("File [" + b + "] does not exist."); 048 } 049 050 // Implements the following by reflection 051 052 try { 053 Path pathA = a.toPath(); 054 Path pathB = b.toPath(); 055 056 FileStore fileStoreA = Files.getFileStore(pathA); 057 FileStore fileStoreB = Files.getFileStore(pathB); 058 059 return fileStoreA.equals(fileStoreB); 060 } catch (Exception e) { 061 throw new RolloverFailure("Failed to check file store equality for [" + a + "] and [" + b + "]", e); 062 } 063 } 064}