UnixFileSystem.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class UnixFileSystem extends FileSystem {
private final char slash;
private final char colon;
public UnixFileSystem() {
new GetPropertyAction("java.home"));
}
/* -- Normalization and construction -- */
public char getSeparator() {
return slash;
}
public char getPathSeparator() {
return colon;
}
/* A normal Unix pathname contains no duplicate slashes and does not end
with a slash. It may be the empty string. */
/* Normalize the given pathname, whose length is len, starting at the given
offset; everything before this offset is already normal. */
int n = len;
if (n == 0) return "/";
char prevChar = 0;
for (int i = off; i < n; i++) {
prevChar = c;
}
}
/* Check that the given pathname is normal. If not, invoke the real
normalizer on the part of the pathname that requires normalization.
This way we iterate through the whole pathname string only once. */
char prevChar = 0;
for (int i = 0; i < n; i++) {
prevChar = c;
}
return pathname;
}
}
}
}
public String getDefaultParent() {
return "/";
}
// "/foo/" --> "/foo", but "/" --> "/"
}
return p;
}
/* -- Path operations -- */
public boolean isAbsolute(File f) {
return (f.getPrefixLength() != 0);
}
if (isAbsolute(f)) return f.getPath();
}
// Caches for canonicalization results to improve startup performance.
// The first cache handles repeated canonicalizations of the same path
// name. The prefix cache handles repeated canonicalizations within the
// same directory, and must not create results differing from the true
// canonicalization algorithm in canonicalize_md.c. For this reason the
// prefix cache is conservative and is not used for complex path names.
// On Unix symlinks can jump anywhere in the file system, so we only
// treat prefixes in java.home as trusted and cacheable in the
// canonicalization algorithm
if (!useCanonCaches) {
return canonicalize0(path);
} else {
if (useCanonPrefixCache) {
// Note that this can cause symlinks that should
// be resolved to a destination directory to be
// resolved to the directory they're contained in
// Hit only in prefix cache; full path is canonical
}
}
}
if (useCanonPrefixCache &&
// Note that we don't allow a resolved symlink
// to elsewhere in java.home to pollute the
// prefix cache (java.home prefix cache could
// just as easily be a set at this point)
if (f.exists() && !f.isDirectory()) {
}
}
}
}
}
return res;
}
}
// Best-effort attempt to get parent of this path; used for
// optimization of filename canonicalization. This must return null for
// any cases where the code in canonicalize_md.c would throw an
// exception or otherwise deal with non-simple pathnames like handling
// of "." and "..". It may conservatively return null in other
// situations as well. Returning null will cause the underlying
// (expensive) canonicalization routine to be called.
int adjacentDots = 0;
int nonDotCount = 0;
while (idx > 0) {
if (c == '.') {
if (++adjacentDots >= 2) {
// Punt on pathnames containing . and ..
return null;
}
} else if (c == sep) {
// Punt on pathnames containing . and ..
return null;
}
if (idx == 0 ||
// Punt on pathnames containing adjacent slashes
// toward the end
return null;
}
} else {
++nonDotCount;
adjacentDots = 0;
}
--idx;
}
return null;
}
/* -- Attribute accessors -- */
public native int getBooleanAttributes0(File f);
public int getBooleanAttributes(File f) {
int rv = getBooleanAttributes0(f);
}
public native long getLastModifiedTime(File f);
/* -- File operations -- */
throws IOException;
// Keep canonicalization caches in sync after file deletion
// and renaming operations. Could be more clever than this
// not worth it since these entries expire after 30 seconds
// anyway.
return delete0(f);
}
public native boolean createDirectory(File f);
// Keep canonicalization caches in sync after file deletion
// and renaming operations. Could be more clever than this
// not worth it since these entries expire after 30 seconds
// anyway.
}
public native boolean setReadOnly(File f);
/* -- Filesystem interface -- */
try {
}
} catch (SecurityException x) {
return new File[0];
}
}
/* -- Disk usage -- */
/* -- Basic infrastructure -- */
}
}
private static native void initIDs();
static {
initIDs();
}
}