summaryrefslogtreecommitdiff
path: root/salhelper
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-05-25 08:52:54 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-05-25 08:57:24 +0100
commitae59ac86469e5e001cc4e274f5c2fd5258621ae1 (patch)
treea74d98d5bccbc451713b5efd6ba0e3b30db86ab2 /salhelper
parentc877cb39f176a9bb1a65c1844a495762ef635100 (diff)
add salhelper::LinkResolver
Diffstat (limited to 'salhelper')
-rw-r--r--salhelper/inc/salhelper/linkhelper.hxx93
-rw-r--r--salhelper/prj/d.lst1
2 files changed, 94 insertions, 0 deletions
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