/src/libreoffice/include/salhelper/linkhelper.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | /* |
11 | | * This file is part of LibreOffice published API. |
12 | | */ |
13 | | |
14 | | #ifndef INCLUDED_SALHELPER_LINKHELPER_HXX |
15 | | #define INCLUDED_SALHELPER_LINKHELPER_HXX |
16 | | |
17 | | #include "rtl/ustring.hxx" |
18 | | #include "osl/file.hxx" |
19 | | |
20 | | namespace salhelper |
21 | | { |
22 | | class SAL_WARN_UNUSED LinkResolver |
23 | | { |
24 | | public: |
25 | | osl::FileStatus m_aStatus; |
26 | | |
27 | | LinkResolver(sal_uInt32 nMask) |
28 | 0 | : m_aStatus(nMask | |
29 | 0 | osl_FileStatus_Mask_FileURL | |
30 | 0 | osl_FileStatus_Mask_Type | |
31 | 0 | osl_FileStatus_Mask_LinkTargetURL) |
32 | 0 | { |
33 | 0 | } |
34 | | |
35 | | /** Resolve a file url if it's a symbolic link, to a maximum depth of |
36 | | * nDepth and fill in m_aStatus with the requested ctor flags |
37 | | * |
38 | | * @return osl::FileBase::E_None on success |
39 | | * |
40 | | * @see DirectoryItem::getFileStatus |
41 | | */ |
42 | | osl::FileBase::RC fetchFileStatus(const rtl::OUString &rURL, |
43 | | int nDepth = 128) |
44 | 0 | { |
45 | | //In an ideal world this wouldn't be inline, but I want to use this |
46 | | //in jvmfwk hence salhelper, but salhelper is .map controlled and |
47 | | //getting all the mangled names right is a misery, moving it over |
48 | | //to visibility markup would drop per-symbol versioning |
49 | 0 | osl::FileBase::RC eReturn; |
50 | |
|
51 | 0 | osl::DirectoryItem item; |
52 | 0 | rtl::OUString sURL(rURL); |
53 | 0 | while ((eReturn = osl::DirectoryItem::get(sURL, item)) |
54 | 0 | == osl::File::E_None) |
55 | 0 | { |
56 | 0 | if (--nDepth == 0) |
57 | 0 | { |
58 | 0 | eReturn = osl::FileBase::E_MULTIHOP; |
59 | 0 | break; |
60 | 0 | } |
61 | 0 | eReturn = item.getFileStatus(m_aStatus); |
62 | 0 | if (eReturn != osl::File::E_None) |
63 | 0 | break; |
64 | 0 | if (m_aStatus.getFileType() != osl::FileStatus::Link) |
65 | 0 | { |
66 | 0 | eReturn = osl::FileBase::E_None; |
67 | 0 | break; |
68 | 0 | } |
69 | 0 | sURL = m_aStatus.getLinkTargetURL(); |
70 | 0 | } |
71 | |
|
72 | 0 | return eReturn; |
73 | 0 | } |
74 | | }; |
75 | | } |
76 | | |
77 | | #endif |
78 | | |
79 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |