diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-05-25 08:52:54 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-05-25 08:57:24 +0100 |
commit | ae59ac86469e5e001cc4e274f5c2fd5258621ae1 (patch) | |
tree | a74d98d5bccbc451713b5efd6ba0e3b30db86ab2 | |
parent | c877cb39f176a9bb1a65c1844a495762ef635100 (diff) |
add salhelper::LinkResolver
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/makefile.mk | 7 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 46 | ||||
-rw-r--r-- | salhelper/inc/salhelper/linkhelper.hxx | 93 | ||||
-rw-r--r-- | salhelper/prj/d.lst | 1 |
4 files changed, 110 insertions, 37 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk b/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk index 9640bf887a2e..5b09a67952c5 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk +++ b/jvmfwk/plugins/sunmajor/pluginlib/makefile.mk @@ -59,11 +59,10 @@ SHL1TARGET= $(UNOCOMPONENT1) SHL1STDLIBS= \ - $(CPPULIB) \ $(CPPUHELPER) \ - $(COMPHELPERLIB) \ - $(SALLIB) \ - $(SALHELPERLIB) + $(CPPULIB) \ + $(SALHELPERLIB) \ + $(SALLIB) .IF "$(GUI)" == "WNT" diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index 6cbfb73ebfe0..00843ec8f03a 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -39,7 +39,7 @@ #include "rtl/byteseq.hxx" #include "rtl/ustrbuf.hxx" #include "rtl/instance.hxx" -#include <comphelper/linkhelper.hxx> +#include <salhelper/linkhelper.hxx> #include "boost/scoped_array.hpp" #include "com/sun/star/uno/Sequence.hxx" #include <utility> @@ -822,31 +822,21 @@ bool getJREInfoByPath(const rtl::OUString& path, */ OUString resolveDirPath(const OUString & path) { - OUString sResolved = path; - - if (!comphelper::resolveLink(sResolved)) - return OUString(); - OUString ret; - - //check if this is a directory - DirectoryItem item; - if (DirectoryItem::get(sResolved, item) == File::E_None) + salhelper::LinkResolver aResolver(osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_FileURL); + if (aResolver.fetchFileStatus(path) == osl::FileBase::E_None) { - FileStatus status(osl_FileStatus_Mask_Type | - osl_FileStatus_Mask_FileURL); - - if (item.getFileStatus(status) == File::E_None - && status.getFileType() == FileStatus::Directory) + //check if this is a directory + if (aResolver.m_aStatus.getFileType() == FileStatus::Directory) { #ifndef JVM_ONE_PATH_CHECK - ret = sResolved; + ret = aResolver.m_aStatus.getFileURL(); #else ret = path; #endif } } - return ret; } /** Checks if the path is a file. If it is a link to a file than @@ -854,31 +844,21 @@ OUString resolveDirPath(const OUString & path) */ OUString resolveFilePath(const OUString & path) { - OUString sResolved = path; - - if (!comphelper::resolveLink(sResolved)) - return OUString(); - OUString ret; - - //check if this is a valid path to a file or and if it is a link - DirectoryItem item; - if (DirectoryItem::get(sResolved, item) == File::E_None) + salhelper::LinkResolver aResolver(osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_FileURL); + if (aResolver.fetchFileStatus(path) == osl::FileBase::E_None) { - FileStatus status(osl_FileStatus_Mask_Type | - osl_FileStatus_Mask_FileURL); - - if (item.getFileStatus(status) == File::E_None - && status.getFileType() == FileStatus::Regular) + //check if this is a file + if (aResolver.m_aStatus.getFileType() == FileStatus::Regular) { #ifndef JVM_ONE_PATH_CHECK - ret = sResolved; + ret = aResolver.m_aStatus.getFileURL(); #else ret = path; #endif } } - return ret; } diff --git a/salhelper/inc/salhelper/linkhelper.hxx b/salhelper/inc/salhelper/linkhelper.hxx new file mode 100644 index 000000000000..c8744dcca0b4 --- /dev/null +++ b/salhelper/inc/salhelper/linkhelper.hxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.) + * Portions created by the Initial Developer are Copyright (C) 2011 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Caolán McNamara <caolanm@redhat.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef _SALHELPER_LINKHELPER_HXX +#define _SALHELPER_LINKHELPER_HXX + +#include <rtl/ustring.hxx> +#include <osl/file.hxx> + +namespace salhelper +{ + class LinkResolver + { + public: + osl::FileStatus m_aStatus; + + LinkResolver(sal_uInt32 nMask) + : m_aStatus(nMask | + osl_FileStatus_Mask_FileURL | + osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_LinkTargetURL) + { + } + + /** Resolve a file url if its a symbolic link, to a maximum depth of + * nDepth and fill in m_aStatus with the requested ctor flags + * + * @return osl::FileBase::E_None on success + * + * @see DirectoryItem::getFileStatus + */ + osl::FileBase::RC fetchFileStatus(const rtl::OUString &rURL, + int nDepth = 128) + { + //In an ideal world this wouldn't be inline, but I want to use this + //in jvmfwk hence salhelper, but salhelper is .map controlled and + //getting all the mangled names right is a misery, moving it over + //to visibility markup would drop per-symbol versioning + osl::FileBase::RC eReturn; + + osl::DirectoryItem item; + rtl::OUString sURL(rURL); + while ((eReturn = osl::DirectoryItem::get(sURL, item)) + == osl::File::E_None) + { + if (--nDepth == 0) + { + eReturn = osl::FileBase::E_MULTIHOP; + break; + } + eReturn = item.getFileStatus(m_aStatus); + if (eReturn != osl::File::E_None) + break; + if (m_aStatus.getFileType() != osl::FileStatus::Link) + { + eReturn = osl::FileBase::E_None; + break; + } + sURL = m_aStatus.getLinkTargetURL(); + } + + return eReturn; + } + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/salhelper/prj/d.lst b/salhelper/prj/d.lst index 86b44d0420bd..a0769a40d3b5 100644 --- a/salhelper/prj/d.lst +++ b/salhelper/prj/d.lst @@ -6,6 +6,7 @@ mkdir: %_DEST%\inc%_EXT%\salhelper ..\inc\salhelper\futurequeue.hxx %_DEST%\inc%_EXT%\salhelper\futurequeue.hxx ..\inc\salhelper\monitor.hxx %_DEST%\inc%_EXT%\salhelper\monitor.hxx ..\inc\salhelper\queue.hxx %_DEST%\inc%_EXT%\salhelper\queue.hxx +..\inc\salhelper\linkhelper.hxx %_DEST%\inc%_EXT%\salhelper\linkhelper.hxx ..\inc\salhelper\refobj.hxx %_DEST%\inc%_EXT%\salhelper\refobj.hxx ..\inc\salhelper\simplereferenceobject.hxx %_DEST%\inc%_EXT%\salhelper\simplereferenceobject.hxx ..\inc\salhelper\singletonref.hxx %_DEST%\inc%_EXT%\salhelper\singletonref.hxx |