Avoid potential negative array index access to cached text.
[LibreOffice.git] / unotools / source / ucbhelper / localfilehelper.cxx
blobbdabd5f0ac69917d73ae2c7f313460cd33d78ee1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/DirectoryHelper.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <comphelper/sequence.hxx>
26 #include <sal/log.hxx>
27 #include <unotools/localfilehelper.hxx>
28 #include <rtl/ustring.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <vector>
32 using namespace ::osl;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::ucb;
36 namespace utl
39 css::uno::Sequence < OUString > LocalFileHelper::GetFolderContents( const OUString& rFolder, bool bFolder )
41 std::vector< OUString > vFiles;
42 try
44 ::ucbhelper::Content aCnt(
45 rFolder, Reference< XCommandEnvironment >(),
46 comphelper::getProcessComponentContext() );
47 Reference< css::sdbc::XResultSet > xResultSet;
48 css::uno::Sequence< OUString > aProps { "Url" };
50 try
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& )
58 catch( Exception& )
62 if ( xResultSet.is() )
64 Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
65 try
67 while ( xResultSet->next() )
68 vFiles.push_back( xContentAccess->queryContentIdentifierString() );
70 catch( css::ucb::CommandAbortedException& )
73 catch( Exception& )
78 catch( Exception& )
82 return comphelper::containerToSequence(vFiles);
85 void removeTree(OUString const & url) {
86 const bool bError = comphelper::DirectoryHelper::deleteDirRecursively(url);
87 SAL_WARN_IF(bError, "desktop.app", "error removing directory " << url);
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */