2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 893N/A * Utility methods for symbolic link support on Windows Vista and newer. 893N/A * Returns the target of a symbolic link 1576N/A * Returns the final path (all symbolic links resolved) or null if this 1576N/A * operation is not supported. 1576N/A // ERROR_INVALID_LEVEL is the error returned when not supported 1576N/A // (a sym link to file on FAT32 or Samba server for example) 893N/A * Returns the final path of a given path as a String. This should be used 893N/A * prior to calling Win32 system calls that do not follow links. 893N/A // if not following links then don't need final path 1319N/A // if file is not a sym link then don't need final path 1576N/A // The file is a symbolic link so attempt to get the final path 893N/A // Fallback: read target of link, resolve against parent, and repeat 893N/A // until file is not a link. 893N/A // non a link so we are done 893N/A // no parent so use parent of absolute path 893N/A * Returns the actual path of a file, optionally resolving all symbolic 893N/A // Start with absolute path 893N/A // Collapse "." and ".." 893N/A // string builder to build up components of path 893N/A // UNC pathname, begins with "\\\\host\\share" 893N/A // skip both server and share names 893N/A // The UNC does not have a share name (collapsed by GetFullPathName) 1576N/A // if the result is only a root component then we simply check it exists 893N/A // iterate through each component to get its actual name in the 1576N/A // if a reparse point is encountered then we must return the 1576N/A // Fallback to slow path, usually because there is a sym 1576N/A // link to a file system that doesn't support sym links. 1576N/A // add the name to the result 893N/A * Returns target of a symbolic link given the handle of an open file 893N/A * (that should be a link). 893N/A // FIXME: exception doesn't have file name 893N/A * typedef struct _REPARSE_DATA_BUFFER { 893N/A * USHORT ReparseDataLength; 893N/A * USHORT SubstituteNameOffset; 893N/A * USHORT SubstituteNameLength; 893N/A * USHORT PrintNameOffset; 893N/A * USHORT PrintNameLength; 893N/A * } SymbolicLinkReparseBuffer; 893N/A * USHORT SubstituteNameOffset; 893N/A * USHORT SubstituteNameLength; 893N/A * USHORT PrintNameOffset; 893N/A * USHORT PrintNameLength; 893N/A * } MountPointReparseBuffer; 893N/A * } GenericReparseBuffer; 893N/A * } REPARSE_DATA_BUFFER 893N/A // FIXME: exception doesn't have file name 893N/A // get offset and length of target 893N/A // copy into char array 893N/A // remove special prefix 893N/A * Resolve all symbolic-links in a given absolute and normalized path 893N/A // iterate through each name element of the path, resolving links as 893N/A * If a symbolic link then we resolve it against the parent 893N/A * of the current name element. We then resolve any remaining 893N/A * part of the path against the result. The target of the link 893N/A * may have "." and ".." components so re-normalize and restart 893N/A * the process from the first element. 893N/A * Strip long path or symbolic link prefix from path 893N/A // prefix for target of symbolic link