1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/sdbc/XResultSet.hpp>
21 #include <com/sun/star/ucb/XContentAccess.hpp>
22 #include <com/sun/star/ucb/CommandAbortedException.hpp>
23 #include <comphelper/processfactory.hxx>
24 #include <comphelper/sequence.hxx>
25 #include <sal/log.hxx>
26 #include <unotools/localfilehelper.hxx>
27 #include <rtl/ustring.hxx>
28 #include <osl/file.hxx>
29 #include <ucbhelper/content.hxx>
32 using namespace ::osl
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::ucb
;
39 css::uno::Sequence
< OUString
> LocalFileHelper::GetFolderContents( const OUString
& rFolder
, bool bFolder
)
41 std::vector
< OUString
> vFiles
;
44 ::ucbhelper::Content
aCnt(
45 rFolder
, Reference
< XCommandEnvironment
>(),
46 comphelper::getProcessComponentContext() );
47 Reference
< css::sdbc::XResultSet
> xResultSet
;
48 css::uno::Sequence
< OUString
> aProps
{ "Url" };
52 ::ucbhelper::ResultSetInclude eInclude
= bFolder
? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS
: ::ucbhelper::INCLUDE_DOCUMENTS_ONLY
;
53 xResultSet
= aCnt
.createCursor( aProps
, eInclude
);
55 catch( css::ucb::CommandAbortedException
& )
62 if ( xResultSet
.is() )
64 Reference
< XContentAccess
> xContentAccess( xResultSet
, UNO_QUERY
);
67 while ( xResultSet
->next() )
68 vFiles
.push_back( xContentAccess
->queryContentIdentifierString() );
70 catch( css::ucb::CommandAbortedException
& )
82 return comphelper::containerToSequence(vFiles
);
85 void removeTree(OUString
const & url
) {
86 osl::Directory
dir(url
);
87 osl::FileBase::RC rc
= dir
.open();
89 case osl::FileBase::E_None
:
91 case osl::FileBase::E_NOENT
:
92 return; //TODO: SAL_WARN if recursive
94 SAL_WARN("desktop.app", "cannot open directory " << dir
.getURL() << ": " << +rc
);
99 rc
= dir
.getNextItem(i
, SAL_MAX_UINT32
);
100 if (rc
== osl::FileBase::E_NOENT
) {
103 if (rc
!= osl::FileBase::E_None
) {
104 SAL_WARN( "desktop.app", "cannot iterate directory " << dir
.getURL() << ": " << +rc
);
107 osl::FileStatus
stat(
108 osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
|
109 osl_FileStatus_Mask_FileURL
);
110 rc
= i
.getFileStatus(stat
);
111 if (rc
!= osl::FileBase::E_None
) {
112 SAL_WARN( "desktop.app", "cannot stat in directory " << dir
.getURL() << ": " << +rc
);
115 if (stat
.getFileType() == osl::FileStatus::Directory
) { //TODO: symlinks
116 removeTree(stat
.getFileURL());
118 rc
= osl::File::remove(stat
.getFileURL());
120 rc
!= osl::FileBase::E_None
, "desktop.app",
121 "cannot remove file " << stat
.getFileURL() << ": " << +rc
);
127 rc
!= osl::FileBase::E_None
, "desktop.app",
128 "cannot close directory " << dir
.getURL() << ": " << +rc
);
130 rc
= osl::Directory::remove(url
);
132 rc
!= osl::FileBase::E_None
, "desktop.app",
133 "cannot remove directory " << url
<< ": " << +rc
);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */