| 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 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <config_features.h> |
| 21 |
|
| 22 |
#include <sal/config.h> |
| 23 |
#include <sal/log.hxx> |
| 24 |
|
| 25 |
#if HAVE_FEATURE_MACOSX_SANDBOX |
| 26 |
#include <sys/stat.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <com/sun/star/beans/IllegalTypeException.hpp> |
| 30 |
#include <com/sun/star/beans/NotRemoveableException.hpp> |
| 31 |
#include <com/sun/star/beans/PropertyAttribute.hpp> |
| 32 |
#include <com/sun/star/beans/PropertyExistException.hpp> |
| 33 |
#include <com/sun/star/io/BufferSizeExceededException.hpp> |
| 34 |
#include <com/sun/star/io/NotConnectedException.hpp> |
| 35 |
#include <com/sun/star/io/IOException.hpp> |
| 36 |
#include <com/sun/star/lang/IllegalAccessException.hpp> |
| 37 |
#include <com/sun/star/task/InteractionClassification.hpp> |
| 38 |
#include <com/sun/star/ucb/ContentInfoAttribute.hpp> |
| 39 |
#include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp> |
| 40 |
#include <com/sun/star/ucb/IOErrorCode.hpp> |
| 41 |
#include <com/sun/star/ucb/InsertCommandArgument.hpp> |
| 42 |
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> |
| 43 |
#include <com/sun/star/ucb/NameClash.hpp> |
| 44 |
#include <com/sun/star/ucb/OpenCommandArgument.hpp> |
| 45 |
#include <com/sun/star/ucb/Store.hpp> |
| 46 |
#include <com/sun/star/ucb/TransferInfo.hpp> |
| 47 |
#include <comphelper/propertysequence.hxx> |
| 48 |
#include <osl/diagnose.h> |
| 49 |
#include <rtl/ref.hxx> |
| 50 |
#include <rtl/uri.hxx> |
| 51 |
|
| 52 |
#include "filtask.hxx" |
| 53 |
#include "filcmd.hxx" |
| 54 |
#include "filglob.hxx" |
| 55 |
#include "filinpstr.hxx" |
| 56 |
#include "filprp.hxx" |
| 57 |
#include "filrset.hxx" |
| 58 |
#include "filstr.hxx" |
| 59 |
#include "prov.hxx" |
| 60 |
|
| 61 |
/******************************************************************************/ |
| 62 |
/* */ |
| 63 |
/* TaskHandling */ |
| 64 |
/* */ |
| 65 |
/******************************************************************************/ |
| 66 |
|
| 67 |
|
| 68 |
using namespace fileaccess; |
| 69 |
using namespace com::sun::star; |
| 70 |
using namespace com::sun::star::uno; |
| 71 |
using namespace com::sun::star::ucb; |
| 72 |
|
| 73 |
#if OSL_DEBUG_LEVEL > 0 |
| 74 |
#define THROW_WHERE SAL_WHERE |
| 75 |
#else |
| 76 |
#define THROW_WHERE "" |
| 77 |
#endif |
| 78 |
|
| 79 |
TaskManager::UnqPathData::UnqPathData() = default; |
| 80 |
|
| 81 |
TaskManager::UnqPathData::UnqPathData(TaskManager::UnqPathData&&) = default; |
| 82 |
|
| 83 |
|
| 84 |
TaskManager::UnqPathData::~UnqPathData() |
| 85 |
{ |
| 86 |
} |
| 87 |
|
| 88 |
TaskManager::MyProperty::MyProperty( const OUString& thePropertyName ) |
| 89 |
: PropertyName( thePropertyName ) |
| 90 |
, Handle(-1) |
| 91 |
, isNative(false) |
| 92 |
, State(beans::PropertyState_AMBIGUOUS_VALUE) |
| 93 |
, Attributes(0) |
| 94 |
{ |
| 95 |
// empty |
| 96 |
} |
| 97 |
|
| 98 |
TaskManager::MyProperty::MyProperty( bool theisNative, |
| 99 |
const OUString& thePropertyName, |
| 100 |
sal_Int32 theHandle, |
| 101 |
const css::uno::Type& theTyp, |
| 102 |
const css::uno::Any& theValue, |
| 103 |
const css::beans::PropertyState& theState, |
| 104 |
sal_Int16 theAttributes ) |
| 105 |
: PropertyName( thePropertyName ), |
| 106 |
Handle( theHandle ), |
| 107 |
isNative( theisNative ), |
| 108 |
Typ( theTyp ), |
| 109 |
Value( theValue ), |
| 110 |
State( theState ), |
| 111 |
Attributes( theAttributes ) |
| 112 |
{ |
| 113 |
// empty |
| 114 |
} |
| 115 |
|
| 116 |
#include "filinl.hxx" |
| 117 |
|
| 118 |
// Default properties |
| 119 |
|
| 120 |
constexpr OUString Title( u"Title"_ustr ); |
| 121 |
constexpr OUString CasePreservingURL( u"CasePreservingURL"_ustr ); |
| 122 |
constexpr OUString IsDocument( u"IsDocument"_ustr ); |
| 123 |
constexpr OUString IsFolder( u"IsFolder"_ustr ); |
| 124 |
constexpr OUString DateModified( u"DateModified"_ustr ); |
| 125 |
constexpr OUString Size( u"Size"_ustr ); |
| 126 |
constexpr OUString IsVolume( u"IsVolume"_ustr ); |
| 127 |
constexpr OUString IsRemoveable( u"IsRemoveable"_ustr ); |
| 128 |
constexpr OUString IsRemote( u"IsRemote"_ustr ); |
| 129 |
constexpr OUString IsCompactDisc( u"IsCompactDisc"_ustr ); |
| 130 |
constexpr OUString IsFloppy( u"IsFloppy"_ustr ); |
| 131 |
constexpr OUString IsHidden( u"IsHidden"_ustr ); |
| 132 |
constexpr OUString ContentType( u"ContentType"_ustr ); |
| 133 |
constexpr OUString IsReadOnly( u"IsReadOnly"_ustr ); |
| 134 |
constexpr OUString CreatableContentsInfo( u"CreatableContentsInfo"_ustr ); |
| 135 |
|
| 136 |
TaskManager::TaskManager( const uno::Reference< uno::XComponentContext >& rxContext, |
| 137 |
FileProvider* pProvider, bool bWithConfig ) |
| 138 |
: m_nCommandId( 0 ), |
| 139 |
m_pProvider( pProvider ), |
| 140 |
m_xContext( rxContext ), |
| 141 |
// Commands |
| 142 |
m_sCommandInfo{ |
| 143 |
{ /* Name */ u"getCommandInfo"_ustr, |
| 144 |
/* Handle */ -1, |
| 145 |
/* ArgType */ cppu::UnoType<void>::get() }, |
| 146 |
|
| 147 |
{ /* Name */ u"getPropertySetInfo"_ustr, |
| 148 |
/* Handle */ -1, |
| 149 |
/* ArgType */ cppu::UnoType<void>::get() }, |
| 150 |
|
| 151 |
{ /* Name */ u"getPropertyValues"_ustr, |
| 152 |
/* Handle */ -1, |
| 153 |
/* ArgType */ cppu::UnoType<uno::Sequence< beans::Property >>::get() }, |
| 154 |
|
| 155 |
{ /* Name */ u"setPropertyValues"_ustr, |
| 156 |
/* Handle */ -1, |
| 157 |
/* ArgType */ cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get() }, |
| 158 |
|
| 159 |
{ /* Name */ u"open"_ustr, |
| 160 |
/* Handle */ -1, |
| 161 |
/* ArgType */ cppu::UnoType<OpenCommandArgument>::get() }, |
| 162 |
|
| 163 |
{ /* Name */ u"transfer"_ustr, |
| 164 |
/* Handle */ -1, |
| 165 |
/* ArgType */ cppu::UnoType<TransferInfo>::get() }, |
| 166 |
|
| 167 |
{ /* Name */ u"delete"_ustr, |
| 168 |
/* Handle */ -1, |
| 169 |
/* ArgType */ cppu::UnoType<sal_Bool>::get() }, |
| 170 |
|
| 171 |
{ /* Name */ u"insert"_ustr, |
| 172 |
/* Handle */ -1, |
| 173 |
/* ArgType */ cppu::UnoType<InsertCommandArgument>::get() }, |
| 174 |
|
| 175 |
{ /* Name */ u"createNewContent"_ustr, |
| 176 |
/* Handle */ -1, |
| 177 |
/* ArgType */ cppu::UnoType<ucb::ContentInfo>::get() } } |
| 178 |
{ |
| 179 |
// Title |
| 180 |
m_aDefaultProperties.insert( MyProperty( true, |
| 181 |
Title, |
| 182 |
-1 , |
| 183 |
cppu::UnoType<OUString>::get(), |
| 184 |
uno::Any(), |
| 185 |
beans::PropertyState_DEFAULT_VALUE, |
| 186 |
beans::PropertyAttribute::MAYBEVOID |
| 187 |
| beans::PropertyAttribute::BOUND ) ); |
| 188 |
|
| 189 |
// CasePreservingURL |
| 190 |
m_aDefaultProperties.insert( |
| 191 |
MyProperty( true, |
| 192 |
CasePreservingURL, |
| 193 |
-1 , |
| 194 |
cppu::UnoType<OUString>::get(), |
| 195 |
uno::Any(), |
| 196 |
beans::PropertyState_DEFAULT_VALUE, |
| 197 |
beans::PropertyAttribute::MAYBEVOID |
| 198 |
| beans::PropertyAttribute::BOUND |
| 199 |
| beans::PropertyAttribute::READONLY ) ); |
| 200 |
|
| 201 |
|
| 202 |
// IsFolder |
| 203 |
m_aDefaultProperties.insert( MyProperty( true, |
| 204 |
IsFolder, |
| 205 |
-1 , |
| 206 |
cppu::UnoType<sal_Bool>::get(), |
| 207 |
uno::Any(), |
| 208 |
beans::PropertyState_DEFAULT_VALUE, |
| 209 |
beans::PropertyAttribute::MAYBEVOID |
| 210 |
| beans::PropertyAttribute::BOUND |
| 211 |
| beans::PropertyAttribute::READONLY ) ); |
| 212 |
|
| 213 |
|
| 214 |
// IsDocument |
| 215 |
m_aDefaultProperties.insert( MyProperty( true, |
| 216 |
IsDocument, |
| 217 |
-1 , |
| 218 |
cppu::UnoType<sal_Bool>::get(), |
| 219 |
uno::Any(), |
| 220 |
beans::PropertyState_DEFAULT_VALUE, |
| 221 |
beans::PropertyAttribute::MAYBEVOID |
| 222 |
| beans::PropertyAttribute::BOUND |
| 223 |
| beans::PropertyAttribute::READONLY ) ); |
| 224 |
|
| 225 |
// Removable |
| 226 |
m_aDefaultProperties.insert( MyProperty( true, |
| 227 |
IsVolume, |
| 228 |
-1 , |
| 229 |
cppu::UnoType<sal_Bool>::get(), |
| 230 |
uno::Any(), |
| 231 |
beans::PropertyState_DEFAULT_VALUE, |
| 232 |
beans::PropertyAttribute::MAYBEVOID |
| 233 |
| beans::PropertyAttribute::BOUND |
| 234 |
| beans::PropertyAttribute::READONLY ) ); |
| 235 |
|
| 236 |
|
| 237 |
// Removable |
| 238 |
m_aDefaultProperties.insert( MyProperty( true, |
| 239 |
IsRemoveable, |
| 240 |
-1 , |
| 241 |
cppu::UnoType<sal_Bool>::get(), |
| 242 |
uno::Any(), |
| 243 |
beans::PropertyState_DEFAULT_VALUE, |
| 244 |
beans::PropertyAttribute::MAYBEVOID |
| 245 |
| beans::PropertyAttribute::BOUND |
| 246 |
| beans::PropertyAttribute::READONLY ) ); |
| 247 |
|
| 248 |
// Remote |
| 249 |
m_aDefaultProperties.insert( MyProperty( true, |
| 250 |
IsRemote, |
| 251 |
-1 , |
| 252 |
cppu::UnoType<sal_Bool>::get(), |
| 253 |
uno::Any(), |
| 254 |
beans::PropertyState_DEFAULT_VALUE, |
| 255 |
beans::PropertyAttribute::MAYBEVOID |
| 256 |
| beans::PropertyAttribute::BOUND |
| 257 |
| beans::PropertyAttribute::READONLY ) ); |
| 258 |
|
| 259 |
// CompactDisc |
| 260 |
m_aDefaultProperties.insert( MyProperty( true, |
| 261 |
IsCompactDisc, |
| 262 |
-1 , |
| 263 |
cppu::UnoType<sal_Bool>::get(), |
| 264 |
uno::Any(), |
| 265 |
beans::PropertyState_DEFAULT_VALUE, |
| 266 |
beans::PropertyAttribute::MAYBEVOID |
| 267 |
| beans::PropertyAttribute::BOUND |
| 268 |
| beans::PropertyAttribute::READONLY ) ); |
| 269 |
|
| 270 |
// Floppy |
| 271 |
m_aDefaultProperties.insert( MyProperty( true, |
| 272 |
IsFloppy, |
| 273 |
-1 , |
| 274 |
cppu::UnoType<sal_Bool>::get(), |
| 275 |
uno::Any(), |
| 276 |
beans::PropertyState_DEFAULT_VALUE, |
| 277 |
beans::PropertyAttribute::MAYBEVOID |
| 278 |
| beans::PropertyAttribute::BOUND |
| 279 |
| beans::PropertyAttribute::READONLY ) ); |
| 280 |
|
| 281 |
// Hidden |
| 282 |
m_aDefaultProperties.insert( |
| 283 |
MyProperty( |
| 284 |
true, |
| 285 |
IsHidden, |
| 286 |
-1 , |
| 287 |
cppu::UnoType<sal_Bool>::get(), |
| 288 |
uno::Any(), |
| 289 |
beans::PropertyState_DEFAULT_VALUE, |
| 290 |
beans::PropertyAttribute::MAYBEVOID |
| 291 |
| beans::PropertyAttribute::BOUND |
| 292 |
#if defined(_WIN32) |
| 293 |
)); |
| 294 |
#else |
| 295 |
| beans::PropertyAttribute::READONLY)); // under unix/linux only readable |
| 296 |
#endif |
| 297 |
|
| 298 |
|
| 299 |
// ContentType |
| 300 |
m_aDefaultProperties.insert( MyProperty( false, |
| 301 |
ContentType, |
| 302 |
-1 , |
| 303 |
cppu::UnoType<OUString>::get(), |
| 304 |
uno::Any(OUString()), |
| 305 |
beans::PropertyState_DEFAULT_VALUE, |
| 306 |
beans::PropertyAttribute::MAYBEVOID |
| 307 |
| beans::PropertyAttribute::BOUND |
| 308 |
| beans::PropertyAttribute::READONLY ) ); |
| 309 |
|
| 310 |
|
| 311 |
// DateModified |
| 312 |
m_aDefaultProperties.insert( MyProperty( true, |
| 313 |
DateModified, |
| 314 |
-1 , |
| 315 |
cppu::UnoType<util::DateTime>::get(), |
| 316 |
uno::Any(), |
| 317 |
beans::PropertyState_DEFAULT_VALUE, |
| 318 |
beans::PropertyAttribute::MAYBEVOID |
| 319 |
| beans::PropertyAttribute::BOUND ) ); |
| 320 |
|
| 321 |
// Size |
| 322 |
m_aDefaultProperties.insert( MyProperty( true, |
| 323 |
Size, |
| 324 |
-1, |
| 325 |
cppu::UnoType<sal_Int64>::get(), |
| 326 |
uno::Any(), |
| 327 |
beans::PropertyState_DEFAULT_VALUE, |
| 328 |
beans::PropertyAttribute::MAYBEVOID |
| 329 |
| beans::PropertyAttribute::BOUND ) ); |
| 330 |
|
| 331 |
// IsReadOnly |
| 332 |
m_aDefaultProperties.insert( MyProperty( true, |
| 333 |
IsReadOnly, |
| 334 |
-1 , |
| 335 |
cppu::UnoType<sal_Bool>::get(), |
| 336 |
uno::Any(), |
| 337 |
beans::PropertyState_DEFAULT_VALUE, |
| 338 |
beans::PropertyAttribute::MAYBEVOID |
| 339 |
| beans::PropertyAttribute::BOUND ) ); |
| 340 |
|
| 341 |
|
| 342 |
// CreatableContentsInfo |
| 343 |
m_aDefaultProperties.insert( MyProperty( true, |
| 344 |
CreatableContentsInfo, |
| 345 |
-1 , |
| 346 |
cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(), |
| 347 |
uno::Any(), |
| 348 |
beans::PropertyState_DEFAULT_VALUE, |
| 349 |
beans::PropertyAttribute::MAYBEVOID |
| 350 |
| beans::PropertyAttribute::BOUND |
| 351 |
| beans::PropertyAttribute::READONLY ) ); |
| 352 |
|
| 353 |
if(bWithConfig) |
| 354 |
{ |
| 355 |
uno::Reference< XPropertySetRegistryFactory > xRegFac = ucb::Store::create( m_xContext ); |
| 356 |
// Open/create a registry |
| 357 |
m_xFileRegistry = xRegFac->createPropertySetRegistry( OUString() ); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
TaskManager::~TaskManager() |
| 363 |
{ |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
void |
| 368 |
TaskManager::startTask( |
| 369 |
sal_Int32 CommandId, |
| 370 |
const uno::Reference< XCommandEnvironment >& xCommandEnv ) |
| 371 |
{ |
| 372 |
std::unique_lock aGuard( m_aMutex ); |
| 373 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 374 |
if( it != m_aTaskMap.end() ) |
| 375 |
{ |
| 376 |
throw DuplicateCommandIdentifierException( OSL_LOG_PREFIX ); |
| 377 |
} |
| 378 |
m_aTaskMap.emplace( CommandId, TaskHandling( xCommandEnv )); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
void |
| 383 |
TaskManager::endTask( sal_Int32 CommandId, |
| 384 |
const OUString& aUncPath, |
| 385 |
BaseContent* pContent) |
| 386 |
{ |
| 387 |
std::unique_lock aGuard( m_aMutex ); |
| 388 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 389 |
if( it == m_aTaskMap.end() ) |
| 390 |
return; |
| 391 |
|
| 392 |
TaskHandlerErr ErrorCode = it->second.getInstalledError(); |
| 393 |
sal_Int32 MinorCode = it->second.getMinorErrorCode(); |
| 394 |
bool isHandled = it->second.isHandled(); |
| 395 |
|
| 396 |
Reference< XCommandEnvironment > xComEnv |
| 397 |
= it->second.getCommandEnvironment(); |
| 398 |
|
| 399 |
m_aTaskMap.erase( it ); |
| 400 |
|
| 401 |
aGuard.unlock(); |
| 402 |
|
| 403 |
if( ErrorCode != TaskHandlerErr::NO_ERROR ) |
| 404 |
throw_handler( |
| 405 |
ErrorCode, |
| 406 |
MinorCode, |
| 407 |
xComEnv, |
| 408 |
aUncPath, |
| 409 |
pContent, |
| 410 |
isHandled); |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
void TaskManager::clearError( sal_Int32 CommandId ) |
| 415 |
{ |
| 416 |
std::unique_lock aGuard( m_aMutex ); |
| 417 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 418 |
if( it != m_aTaskMap.end() ) |
| 419 |
it->second.clearError(); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
void TaskManager::retrieveError( sal_Int32 CommandId, |
| 424 |
TaskHandlerErr &ErrorCode, |
| 425 |
sal_Int32 &minorCode) |
| 426 |
{ |
| 427 |
std::unique_lock aGuard( m_aMutex ); |
| 428 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 429 |
if( it != m_aTaskMap.end() ) |
| 430 |
{ |
| 431 |
ErrorCode = it->second.getInstalledError(); |
| 432 |
minorCode = it->second. getMinorErrorCode(); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
void TaskManager::installError( sal_Int32 CommandId, |
| 438 |
TaskHandlerErr ErrorCode, |
| 439 |
sal_Int32 MinorCode ) |
| 440 |
{ |
| 441 |
std::unique_lock aGuard( m_aMutex ); |
| 442 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 443 |
if( it != m_aTaskMap.end() ) |
| 444 |
it->second.installError( ErrorCode,MinorCode ); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
sal_Int32 |
| 449 |
TaskManager::getCommandId() |
| 450 |
{ |
| 451 |
std::unique_lock aGuard( m_aMutex ); |
| 452 |
return ++m_nCommandId; |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
void TaskManager::handleTask( |
| 457 |
sal_Int32 CommandId, |
| 458 |
const uno::Reference< task::XInteractionRequest >& request ) |
| 459 |
{ |
| 460 |
std::unique_lock aGuard( m_aMutex ); |
| 461 |
TaskMap::iterator it = m_aTaskMap.find( CommandId ); |
| 462 |
uno::Reference< task::XInteractionHandler > xInt; |
| 463 |
if( it != m_aTaskMap.end() ) |
| 464 |
{ |
| 465 |
xInt = it->second.getInteractionHandler(); |
| 466 |
if( xInt.is() ) |
| 467 |
xInt->handle( request ); |
| 468 |
it->second.setHandled(); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
/*********************************************************************************/ |
| 473 |
/* */ |
| 474 |
/* de/registerNotifier-Implementation */ |
| 475 |
/* */ |
| 476 |
/*********************************************************************************/ |
| 477 |
|
| 478 |
|
| 479 |
// This two methods register and deregister a change listener for the content belonging |
| 480 |
// to URL aUnqPath |
| 481 |
|
| 482 |
|
| 483 |
void |
| 484 |
TaskManager::registerNotifier( const OUString& aUnqPath, Notifier* pNotifier ) |
| 485 |
{ |
| 486 |
std::unique_lock aGuard( m_aMutex ); |
| 487 |
|
| 488 |
ContentMap::iterator it = |
| 489 |
m_aContent.emplace( aUnqPath, UnqPathData() ).first; |
| 490 |
|
| 491 |
std::vector< Notifier* >& nlist = it->second.notifier; |
| 492 |
|
| 493 |
std::vector<Notifier*>::iterator it1 = std::find(nlist.begin(), nlist.end(), pNotifier); |
| 494 |
if( it1 != nlist.end() ) // Every "Notifier" only once |
| 495 |
{ |
| 496 |
return; |
| 497 |
} |
| 498 |
nlist.push_back( pNotifier ); |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
void |
| 503 |
TaskManager::deregisterNotifier( const OUString& aUnqPath,Notifier* pNotifier ) |
| 504 |
{ |
| 505 |
std::unique_lock aGuard( m_aMutex ); |
| 506 |
|
| 507 |
ContentMap::iterator it = m_aContent.find( aUnqPath ); |
| 508 |
if( it == m_aContent.end() ) |
| 509 |
return; |
| 510 |
|
| 511 |
std::erase(it->second.notifier, pNotifier); |
| 512 |
|
| 513 |
if( it->second.notifier.empty() ) |
| 514 |
m_aContent.erase( it ); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
/*********************************************************************************/ |
| 519 |
/* */ |
| 520 |
/* de/associate-Implementation */ |
| 521 |
/* */ |
| 522 |
/*********************************************************************************/ |
| 523 |
|
| 524 |
// Used to associate and deassociate a new property with |
| 525 |
// the content belonging to URL UnqPath. |
| 526 |
// The default value and the attributes are input |
| 527 |
|
| 528 |
|
| 529 |
void |
| 530 |
TaskManager::associate( const OUString& aUnqPath, |
| 531 |
const OUString& PropertyName, |
| 532 |
const uno::Any& DefaultValue, |
| 533 |
const sal_Int16 Attributes ) |
| 534 |
{ |
| 535 |
MyProperty newProperty( false, |
| 536 |
PropertyName, |
| 537 |
-1, |
| 538 |
DefaultValue.getValueType(), |
| 539 |
DefaultValue, |
| 540 |
beans::PropertyState_DEFAULT_VALUE, |
| 541 |
Attributes ); |
| 542 |
|
| 543 |
auto it1 = m_aDefaultProperties.find( newProperty ); |
| 544 |
if( it1 != m_aDefaultProperties.end() ) |
| 545 |
throw beans::PropertyExistException( THROW_WHERE ); |
| 546 |
|
| 547 |
{ |
| 548 |
std::unique_lock aGuard( m_aMutex ); |
| 549 |
|
| 550 |
ContentMap::iterator it = m_aContent.emplace( aUnqPath,UnqPathData() ).first; |
| 551 |
|
| 552 |
// Load the XPersistentPropertySetInfo and create it, if it does not exist |
| 553 |
load( it,true ); |
| 554 |
|
| 555 |
PropertySet& properties = it->second.properties; |
| 556 |
it1 = properties.find( newProperty ); |
| 557 |
if( it1 != properties.end() ) |
| 558 |
throw beans::PropertyExistException(THROW_WHERE ); |
| 559 |
|
| 560 |
// Property does not exist |
| 561 |
properties.insert( newProperty ); |
| 562 |
it->second.xC->addProperty( PropertyName,Attributes,DefaultValue ); |
| 563 |
} |
| 564 |
notifyPropertyAdded( getPropertySetListeners( aUnqPath ), PropertyName ); |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
void |
| 569 |
TaskManager::deassociate( const OUString& aUnqPath, |
| 570 |
const OUString& PropertyName ) |
| 571 |
{ |
| 572 |
MyProperty oldProperty( PropertyName ); |
| 573 |
|
| 574 |
auto it1 = m_aDefaultProperties.find( oldProperty ); |
| 575 |
if( it1 != m_aDefaultProperties.end() ) |
| 576 |
throw beans::NotRemoveableException( THROW_WHERE ); |
| 577 |
|
| 578 |
std::unique_lock aGuard( m_aMutex ); |
| 579 |
|
| 580 |
ContentMap::iterator it = m_aContent.emplace( aUnqPath,UnqPathData() ).first; |
| 581 |
|
| 582 |
load( it, false ); |
| 583 |
|
| 584 |
PropertySet& properties = it->second.properties; |
| 585 |
|
| 586 |
it1 = properties.find( oldProperty ); |
| 587 |
if( it1 == properties.end() ) |
| 588 |
throw beans::UnknownPropertyException( PropertyName ); |
| 589 |
|
| 590 |
properties.erase( it1 ); |
| 591 |
|
| 592 |
if( it->second.xC.is() ) |
| 593 |
it->second.xC->removeProperty( PropertyName ); |
| 594 |
|
| 595 |
if( properties.size() == 9 ) |
| 596 |
{ |
| 597 |
MyProperty ContentTProperty( ContentType ); |
| 598 |
|
| 599 |
if( properties.find( ContentTProperty )->getState() == beans::PropertyState_DEFAULT_VALUE ) |
| 600 |
{ |
| 601 |
it->second.xS = nullptr; |
| 602 |
it->second.xC = nullptr; |
| 603 |
it->second.xA = nullptr; |
| 604 |
if(m_xFileRegistry.is()) |
| 605 |
m_xFileRegistry->removePropertySet( aUnqPath ); |
| 606 |
} |
| 607 |
} |
| 608 |
aGuard.unlock(); |
| 609 |
notifyPropertyRemoved( getPropertySetListeners( aUnqPath ), PropertyName ); |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
/*********************************************************************************/ |
| 614 |
/* */ |
| 615 |
/* page-Implementation */ |
| 616 |
/* */ |
| 617 |
/*********************************************************************************/ |
| 618 |
|
| 619 |
// Given an xOutputStream, this method writes the content of the file belonging to |
| 620 |
// URL aUnqPath into the XOutputStream |
| 621 |
|
| 622 |
|
| 623 |
void TaskManager::page( sal_Int32 CommandId, |
| 624 |
const OUString& aUnqPath, |
| 625 |
const uno::Reference< io::XOutputStream >& xOutputStream ) |
| 626 |
{ |
| 627 |
osl::File aFile( aUnqPath ); |
| 628 |
osl::FileBase::RC err = aFile.open( osl_File_OpenFlag_Read ); |
| 629 |
|
| 630 |
if( err != osl::FileBase::E_None ) |
| 631 |
{ |
| 632 |
aFile.close(); |
| 633 |
installError( CommandId, |
| 634 |
TaskHandlerErr::OPEN_FILE_FOR_PAGING, |
| 635 |
err ); |
| 636 |
return; |
| 637 |
} |
| 638 |
|
| 639 |
const sal_uInt64 bfz = 4*1024; |
| 640 |
sal_Int8 BFF[bfz]; |
| 641 |
sal_uInt64 nrc; // Retrieved number of Bytes; |
| 642 |
|
| 643 |
do |
| 644 |
{ |
| 645 |
err = aFile.read( static_cast<void*>(BFF),bfz,nrc ); |
| 646 |
if( err == osl::FileBase::E_None ) |
| 647 |
{ |
| 648 |
uno::Sequence< sal_Int8 > seq( BFF, static_cast<sal_uInt32>(nrc) ); |
| 649 |
try |
| 650 |
{ |
| 651 |
xOutputStream->writeBytes( seq ); |
| 652 |
} |
| 653 |
catch (const io::NotConnectedException&) |
| 654 |
{ |
| 655 |
installError( CommandId, |
| 656 |
TaskHandlerErr::NOTCONNECTED_FOR_PAGING ); |
| 657 |
break; |
| 658 |
} |
| 659 |
catch (const io::BufferSizeExceededException&) |
| 660 |
{ |
| 661 |
installError( CommandId, |
| 662 |
TaskHandlerErr::BUFFERSIZEEXCEEDED_FOR_PAGING ); |
| 663 |
break; |
| 664 |
} |
| 665 |
catch (const io::IOException&) |
| 666 |
{ |
| 667 |
installError( CommandId, |
| 668 |
TaskHandlerErr::IOEXCEPTION_FOR_PAGING ); |
| 669 |
break; |
| 670 |
} |
| 671 |
} |
| 672 |
else |
| 673 |
{ |
| 674 |
installError( CommandId, |
| 675 |
TaskHandlerErr::READING_FILE_FOR_PAGING, |
| 676 |
err ); |
| 677 |
break; |
| 678 |
} |
| 679 |
} while( nrc == bfz ); |
| 680 |
|
| 681 |
|
| 682 |
aFile.close(); |
| 683 |
|
| 684 |
|
| 685 |
try |
| 686 |
{ |
| 687 |
xOutputStream->closeOutput(); |
| 688 |
} |
| 689 |
catch (const io::NotConnectedException&) |
| 690 |
{ |
| 691 |
} |
| 692 |
catch (const io::BufferSizeExceededException&) |
| 693 |
{ |
| 694 |
} |
| 695 |
catch (const io::IOException&) |
| 696 |
{ |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
/*********************************************************************************/ |
| 702 |
/* */ |
| 703 |
/* open-Implementation */ |
| 704 |
/* */ |
| 705 |
/*********************************************************************************/ |
| 706 |
|
| 707 |
// Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file. |
| 708 |
|
| 709 |
|
| 710 |
uno::Reference< io::XInputStream > |
| 711 |
TaskManager::open( sal_Int32 CommandId, |
| 712 |
const OUString& aUnqPath, |
| 713 |
bool bLock ) |
| 714 |
{ |
| 715 |
rtl::Reference<XInputStream_impl> pInputStream(new XInputStream_impl( aUnqPath, bLock )); // from filinpstr.hxx |
| 716 |
|
| 717 |
TaskHandlerErr ErrorCode = pInputStream->CtorSuccess(); |
| 718 |
|
| 719 |
if( ErrorCode != TaskHandlerErr::NO_ERROR ) |
| 720 |
{ |
| 721 |
installError( CommandId, |
| 722 |
ErrorCode, |
| 723 |
pInputStream->getMinorError() ); |
| 724 |
|
| 725 |
pInputStream.clear(); |
| 726 |
} |
| 727 |
|
| 728 |
return pInputStream; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
/*********************************************************************************/ |
| 733 |
/* */ |
| 734 |
/* open for read/write access-Implementation */ |
| 735 |
/* */ |
| 736 |
/*********************************************************************************/ |
| 737 |
|
| 738 |
// Given a file URL aUnqPath, this methods returns a XStream which can be used |
| 739 |
// to read and write from/to the file. |
| 740 |
|
| 741 |
|
| 742 |
uno::Reference< io::XStream > |
| 743 |
TaskManager::open_rw( sal_Int32 CommandId, |
| 744 |
const OUString& aUnqPath, |
| 745 |
bool bLock ) |
| 746 |
{ |
| 747 |
rtl::Reference<XStream_impl> pStream(new XStream_impl( aUnqPath, bLock )); // from filstr.hxx |
| 748 |
|
| 749 |
TaskHandlerErr ErrorCode = pStream->CtorSuccess(); |
| 750 |
|
| 751 |
if( ErrorCode != TaskHandlerErr::NO_ERROR ) |
| 752 |
{ |
| 753 |
installError( CommandId, |
| 754 |
ErrorCode, |
| 755 |
pStream->getMinorError() ); |
| 756 |
|
| 757 |
pStream.clear(); |
| 758 |
} |
| 759 |
return pStream; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
/*********************************************************************************/ |
| 764 |
/* */ |
| 765 |
/* ls-Implementation */ |
| 766 |
/* */ |
| 767 |
/*********************************************************************************/ |
| 768 |
|
| 769 |
// This method returns the result set containing the children of the directory belonging |
| 770 |
// to file URL aUnqPath |
| 771 |
|
| 772 |
|
| 773 |
uno::Reference< XDynamicResultSet > |
| 774 |
TaskManager::ls( sal_Int32 CommandId, |
| 775 |
const OUString& aUnqPath, |
| 776 |
const sal_Int32 OpenMode, |
| 777 |
const uno::Sequence< beans::Property >& seq, |
| 778 |
const uno::Sequence< NumberedSortingInfo >& seqSort ) |
| 779 |
{ |
| 780 |
rtl::Reference<XResultSet_impl> p(new XResultSet_impl( this,aUnqPath,OpenMode,seq,seqSort )); |
| 781 |
|
| 782 |
TaskHandlerErr ErrorCode = p->CtorSuccess(); |
| 783 |
|
| 784 |
if( ErrorCode != TaskHandlerErr::NO_ERROR ) |
| 785 |
{ |
| 786 |
installError( CommandId, |
| 787 |
ErrorCode, |
| 788 |
p->getMinorError() ); |
| 789 |
|
| 790 |
p.clear(); |
| 791 |
} |
| 792 |
|
| 793 |
return p; |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
/*********************************************************************************/ |
| 798 |
/* */ |
| 799 |
/* info_c implementation */ |
| 800 |
/* */ |
| 801 |
/*********************************************************************************/ |
| 802 |
// Info for commands |
| 803 |
|
| 804 |
uno::Reference< XCommandInfo > |
| 805 |
TaskManager::info_c() |
| 806 |
{ |
| 807 |
return new XCommandInfo_impl( this ); |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
/*********************************************************************************/ |
| 812 |
/* */ |
| 813 |
/* info_p-Implementation */ |
| 814 |
/* */ |
| 815 |
/*********************************************************************************/ |
| 816 |
// Info for the properties |
| 817 |
|
| 818 |
uno::Reference< beans::XPropertySetInfo > |
| 819 |
TaskManager::info_p( const OUString& aUnqPath ) |
| 820 |
{ |
| 821 |
std::unique_lock aGuard( m_aMutex ); |
| 822 |
return new XPropertySetInfo_impl( this,aUnqPath ); |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
/*********************************************************************************/ |
| 827 |
/* */ |
| 828 |
/* setv-Implementation */ |
| 829 |
/* */ |
| 830 |
/*********************************************************************************/ |
| 831 |
|
| 832 |
// Sets the values of the properties belonging to fileURL aUnqPath |
| 833 |
|
| 834 |
|
| 835 |
uno::Sequence< uno::Any > |
| 836 |
TaskManager::setv( const OUString& aUnqPath, |
| 837 |
const uno::Sequence< beans::PropertyValue >& values ) |
| 838 |
{ |
| 839 |
std::unique_lock aGuard( m_aMutex ); |
| 840 |
|
| 841 |
sal_Int32 propChanged = 0; |
| 842 |
uno::Sequence< uno::Any > ret( values.getLength() ); |
| 843 |
auto retRange = asNonConstRange(ret); |
| 844 |
uno::Sequence< beans::PropertyChangeEvent > seqChanged( values.getLength() ); |
| 845 |
auto seqChangedRange = asNonConstRange(seqChanged); |
| 846 |
|
| 847 |
TaskManager::ContentMap::iterator it = m_aContent.find( aUnqPath ); |
| 848 |
PropertySet& properties = it->second.properties; |
| 849 |
TaskManager::PropertySet::const_iterator it1; |
| 850 |
uno::Any aAny; |
| 851 |
|
| 852 |
for( sal_Int32 i = 0; i < values.getLength(); ++i ) |
| 853 |
{ |
| 854 |
MyProperty toset( values[i].Name ); |
| 855 |
it1 = properties.find( toset ); |
| 856 |
if( it1 == properties.end() ) |
| 857 |
{ |
| 858 |
retRange[i] <<= beans::UnknownPropertyException( THROW_WHERE ); |
| 859 |
continue; |
| 860 |
} |
| 861 |
|
| 862 |
aAny = it1->getValue(); |
| 863 |
if( aAny == values[i].Value ) |
| 864 |
continue; // nothing needs to be changed |
| 865 |
|
| 866 |
if( it1->getAttributes() & beans::PropertyAttribute::READONLY ) |
| 867 |
{ |
| 868 |
retRange[i] <<= lang::IllegalAccessException( THROW_WHERE ); |
| 869 |
continue; |
| 870 |
} |
| 871 |
|
| 872 |
seqChangedRange[ propChanged ].PropertyName = values[i].Name; |
| 873 |
seqChangedRange[ propChanged ].PropertyHandle = -1; |
| 874 |
seqChangedRange[ propChanged ].Further = false; |
| 875 |
seqChangedRange[ propChanged ].OldValue = aAny; |
| 876 |
seqChangedRange[ propChanged++ ].NewValue = values[i].Value; |
| 877 |
|
| 878 |
it1->setValue( values[i].Value ); // Put the new value into the local cash |
| 879 |
|
| 880 |
if( ! it1->IsNative() ) |
| 881 |
{ |
| 882 |
// Also put logical properties into storage |
| 883 |
if( !it->second.xS.is() ) |
| 884 |
load( it, true ); |
| 885 |
|
| 886 |
if( ( values[i].Name == ContentType ) && |
| 887 |
it1->getState() == beans::PropertyState_DEFAULT_VALUE ) |
| 888 |
{ // Special logic for ContentType |
| 889 |
// 09.07.01: Not reached anymore, because ContentType is readonly |
| 890 |
it1->setState( beans::PropertyState_DIRECT_VALUE ); |
| 891 |
it->second.xC->addProperty( values[i].Name, |
| 892 |
beans::PropertyAttribute::MAYBEVOID, |
| 893 |
values[i].Value ); |
| 894 |
} |
| 895 |
|
| 896 |
try |
| 897 |
{ |
| 898 |
it->second.xS->setPropertyValue( values[i].Name,values[i].Value ); |
| 899 |
} |
| 900 |
catch (const uno::Exception&e) |
| 901 |
{ |
| 902 |
--propChanged; // unsuccessful setting |
| 903 |
retRange[i] <<= e; |
| 904 |
} |
| 905 |
} |
| 906 |
else |
| 907 |
{ |
| 908 |
// native properties |
| 909 |
// Setting of physical file properties |
| 910 |
if( values[i].Name == Size ) |
| 911 |
{ |
| 912 |
sal_Int64 newSize = 0; |
| 913 |
if( values[i].Value >>= newSize ) |
| 914 |
{ // valid value for the size |
| 915 |
osl::File aFile(aUnqPath); |
| 916 |
bool err = |
| 917 |
aFile.open(osl_File_OpenFlag_Write) != osl::FileBase::E_None || |
| 918 |
aFile.setSize(sal_uInt64(newSize)) != osl::FileBase::E_None || |
| 919 |
aFile.close() != osl::FileBase::E_None; |
| 920 |
|
| 921 |
if( err ) |
| 922 |
{ |
| 923 |
--propChanged; // unsuccessful setting |
| 924 |
uno::Sequence<uno::Any> names(comphelper::InitAnyPropertySequence( |
| 925 |
{ |
| 926 |
{"Uri", uno::Any(aUnqPath)} |
| 927 |
})); |
| 928 |
retRange[i] <<= InteractiveAugmentedIOException( |
| 929 |
OUString(), |
| 930 |
nullptr, |
| 931 |
task::InteractionClassification_ERROR, |
| 932 |
IOErrorCode_GENERAL, |
| 933 |
names ); |
| 934 |
} |
| 935 |
} |
| 936 |
else |
| 937 |
retRange[i] <<= beans::IllegalTypeException( THROW_WHERE ); |
| 938 |
} |
| 939 |
else if(values[i].Name == IsReadOnly || |
| 940 |
values[i].Name == IsHidden) |
| 941 |
{ |
| 942 |
bool value = false; |
| 943 |
if( values[i].Value >>= value ) |
| 944 |
{ |
| 945 |
osl::DirectoryItem aDirItem; |
| 946 |
osl::FileBase::RC err = |
| 947 |
osl::DirectoryItem::get(aUnqPath,aDirItem); |
| 948 |
sal_uInt64 nAttributes(0); |
| 949 |
if(err == osl::FileBase::E_None) |
| 950 |
{ |
| 951 |
osl::FileStatus aFileStatus(osl_FileStatus_Mask_Attributes); |
| 952 |
err = aDirItem.getFileStatus(aFileStatus); |
| 953 |
if(err == osl::FileBase::E_None && |
| 954 |
aFileStatus.isValid(osl_FileStatus_Mask_Attributes)) |
| 955 |
nAttributes = aFileStatus.getAttributes(); |
| 956 |
} |
| 957 |
// now we have the attributes provided all went well. |
| 958 |
if(err == osl::FileBase::E_None) { |
| 959 |
if(values[i].Name == IsReadOnly) |
| 960 |
{ |
| 961 |
nAttributes &= ~(osl_File_Attribute_OwnWrite | |
| 962 |
osl_File_Attribute_GrpWrite | |
| 963 |
osl_File_Attribute_OthWrite | |
| 964 |
osl_File_Attribute_ReadOnly); |
| 965 |
if(value) |
| 966 |
nAttributes |= osl_File_Attribute_ReadOnly; |
| 967 |
else |
| 968 |
nAttributes |= ( |
| 969 |
osl_File_Attribute_OwnWrite | |
| 970 |
osl_File_Attribute_GrpWrite | |
| 971 |
osl_File_Attribute_OthWrite); |
| 972 |
} |
| 973 |
else if(values[i].Name == IsHidden) |
| 974 |
{ |
| 975 |
nAttributes &= ~(osl_File_Attribute_Hidden); |
| 976 |
if(value) |
| 977 |
nAttributes |= osl_File_Attribute_Hidden; |
| 978 |
} |
| 979 |
err = osl::File::setAttributes( |
| 980 |
aUnqPath,nAttributes); |
| 981 |
} |
| 982 |
|
| 983 |
if( err != osl::FileBase::E_None ) |
| 984 |
{ |
| 985 |
--propChanged; // unsuccessful setting |
| 986 |
uno::Sequence<uno::Any> names(comphelper::InitAnyPropertySequence( |
| 987 |
{ |
| 988 |
{"Uri", uno::Any(aUnqPath)} |
| 989 |
})); |
| 990 |
IOErrorCode ioError; |
| 991 |
switch( err ) |
| 992 |
{ |
| 993 |
case osl::FileBase::E_NOMEM: |
| 994 |
// not enough memory for allocating structures <br> |
| 995 |
ioError = IOErrorCode_OUT_OF_MEMORY; |
| 996 |
break; |
| 997 |
case osl::FileBase::E_INVAL: |
| 998 |
// the format of the parameters was not valid<p> |
| 999 |
ioError = IOErrorCode_INVALID_PARAMETER; |
| 1000 |
break; |
| 1001 |
case osl::FileBase::E_NAMETOOLONG: |
| 1002 |
// File name too long<br> |
| 1003 |
ioError = IOErrorCode_NAME_TOO_LONG; |
| 1004 |
break; |
| 1005 |
case osl::FileBase::E_NOENT: |
| 1006 |
// No such file or directory<br> |
| 1007 |
case osl::FileBase::E_NOLINK: |
| 1008 |
// Link has been severed<br> |
| 1009 |
ioError = IOErrorCode_NOT_EXISTING; |
| 1010 |
break; |
| 1011 |
case osl::FileBase::E_ROFS: |
| 1012 |
// #i4735# handle ROFS transparently |
| 1013 |
// as ACCESS_DENIED |
| 1014 |
case osl::FileBase::E_PERM: |
| 1015 |
case osl::FileBase::E_ACCES: |
| 1016 |
// permission denied<br> |
| 1017 |
ioError = IOErrorCode_ACCESS_DENIED; |
| 1018 |
break; |
| 1019 |
case osl::FileBase::E_LOOP: |
| 1020 |
// Too many symbolic links encountered<br> |
| 1021 |
case osl::FileBase::E_FAULT: |
| 1022 |
// Bad address<br> |
| 1023 |
case osl::FileBase::E_IO: |
| 1024 |
// I/O error<br> |
| 1025 |
case osl::FileBase::E_NOSYS: |
| 1026 |
// Function not implemented<br> |
| 1027 |
case osl::FileBase::E_MULTIHOP: |
| 1028 |
// Multihop attempted<br> |
| 1029 |
case osl::FileBase::E_INTR: |
| 1030 |
// function call was interrupted<p> |
| 1031 |
default: |
| 1032 |
ioError = IOErrorCode_GENERAL; |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
retRange[i] <<= InteractiveAugmentedIOException( |
| 1036 |
OUString(), |
| 1037 |
nullptr, |
| 1038 |
task::InteractionClassification_ERROR, |
| 1039 |
ioError, |
| 1040 |
names ); |
| 1041 |
} |
| 1042 |
} |
| 1043 |
else |
| 1044 |
retRange[i] <<= beans::IllegalTypeException( THROW_WHERE ); |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} // end for |
| 1048 |
|
| 1049 |
aGuard.unlock(); |
| 1050 |
if( propChanged ) |
| 1051 |
{ |
| 1052 |
seqChanged.realloc( propChanged ); |
| 1053 |
notifyPropertyChanges( getPropertyChangeNotifier( aUnqPath ), seqChanged ); |
| 1054 |
} |
| 1055 |
|
| 1056 |
return ret; |
| 1057 |
} |
| 1058 |
|
| 1059 |
/*********************************************************************************/ |
| 1060 |
/* */ |
| 1061 |
/* getv-Implementation */ |
| 1062 |
/* */ |
| 1063 |
/*********************************************************************************/ |
| 1064 |
|
| 1065 |
// Reads the values of the properties belonging to fileURL aUnqPath; |
| 1066 |
// Returns an XRow object containing the values in the requested order. |
| 1067 |
|
| 1068 |
|
| 1069 |
uno::Reference< sdbc::XRow > |
| 1070 |
TaskManager::getv( sal_Int32 CommandId, |
| 1071 |
const OUString& aUnqPath, |
| 1072 |
const uno::Sequence< beans::Property >& properties ) |
| 1073 |
{ |
| 1074 |
uno::Sequence< uno::Any > seq( properties.getLength() ); |
| 1075 |
|
| 1076 |
sal_Int32 n_Mask; |
| 1077 |
getMaskFromProperties( n_Mask,properties ); |
| 1078 |
osl::FileStatus aFileStatus( n_Mask ); |
| 1079 |
|
| 1080 |
osl::DirectoryItem aDirItem; |
| 1081 |
osl::FileBase::RC nError1 = osl::DirectoryItem::get( aUnqPath,aDirItem ); |
| 1082 |
if( nError1 != osl::FileBase::E_None ) |
| 1083 |
installError(CommandId, |
| 1084 |
TaskHandlerErr::OPEN_FILE_FOR_PAGING, // BEAWARE, REUSED |
| 1085 |
nError1); |
| 1086 |
|
| 1087 |
osl::FileBase::RC nError2 = aDirItem.getFileStatus( aFileStatus ); |
| 1088 |
if( nError1 == osl::FileBase::E_None && |
| 1089 |
nError2 != osl::FileBase::E_None ) |
| 1090 |
installError(CommandId, |
| 1091 |
TaskHandlerErr::OPEN_FILE_FOR_PAGING, // BEAWARE, REUSED |
| 1092 |
nError2); |
| 1093 |
|
| 1094 |
{ |
| 1095 |
std::unique_lock aGuard( m_aMutex ); |
| 1096 |
|
| 1097 |
TaskManager::ContentMap::iterator it = m_aContent.find( aUnqPath ); |
| 1098 |
commit( aGuard, it, aFileStatus ); |
| 1099 |
|
| 1100 |
PropertySet& propset = it->second.properties; |
| 1101 |
|
| 1102 |
std::transform(properties.begin(), properties.end(), seq.getArray(), |
| 1103 |
[&propset](const beans::Property& rProp) -> uno::Any { |
| 1104 |
MyProperty readProp( rProp.Name ); |
| 1105 |
auto it1 = propset.find( readProp ); |
| 1106 |
if( it1 == propset.end() ) |
| 1107 |
return uno::Any(); |
| 1108 |
return it1->getValue(); |
| 1109 |
}); |
| 1110 |
} |
| 1111 |
|
| 1112 |
return new XRow_impl( this,seq ); |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
/********************************************************************************/ |
| 1117 |
/* */ |
| 1118 |
/* transfer-commandos */ |
| 1119 |
/* */ |
| 1120 |
/********************************************************************************/ |
| 1121 |
|
| 1122 |
|
| 1123 |
/********************************************************************************/ |
| 1124 |
/* */ |
| 1125 |
/* move-implementation */ |
| 1126 |
/* */ |
| 1127 |
/********************************************************************************/ |
| 1128 |
|
| 1129 |
// Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath. |
| 1130 |
|
| 1131 |
|
| 1132 |
void |
| 1133 |
TaskManager::move( sal_Int32 CommandId, |
| 1134 |
const OUString& srcUnqPath, |
| 1135 |
const OUString& dstUnqPathIn, |
| 1136 |
const sal_Int32 NameClash ) |
| 1137 |
{ |
| 1138 |
// --> #i88446# Method notifyContentExchanged( getContentExchangedEventListeners( srcUnqPath,dstUnqPath,!isDocument ) ); crashes if |
| 1139 |
// srcUnqPath and dstUnqPathIn are equal |
| 1140 |
if( srcUnqPath == dstUnqPathIn ) |
| 1141 |
return; |
| 1142 |
|
| 1143 |
osl::FileBase::RC nError; |
| 1144 |
OUString dstUnqPath( dstUnqPathIn ); |
| 1145 |
|
| 1146 |
switch( NameClash ) |
| 1147 |
{ |
| 1148 |
case NameClash::KEEP: |
| 1149 |
{ |
| 1150 |
nError = osl_File_move( srcUnqPath,dstUnqPath,true ); |
| 1151 |
if( nError != osl::FileBase::E_None && nError != osl::FileBase::E_EXIST ) |
| 1152 |
{ |
| 1153 |
installError( CommandId, |
| 1154 |
TaskHandlerErr::KEEPERROR_FOR_MOVE, |
| 1155 |
nError ); |
| 1156 |
return; |
| 1157 |
} |
| 1158 |
break; |
| 1159 |
} |
| 1160 |
case NameClash::OVERWRITE: |
| 1161 |
{ |
| 1162 |
// stat to determine whether we have a symlink |
| 1163 |
OUString targetPath(dstUnqPath); |
| 1164 |
|
| 1165 |
osl::FileStatus aStatus(osl_FileStatus_Mask_Type|osl_FileStatus_Mask_LinkTargetURL); |
| 1166 |
osl::DirectoryItem aItem; |
| 1167 |
(void)osl::DirectoryItem::get(dstUnqPath,aItem); |
| 1168 |
(void)aItem.getFileStatus(aStatus); |
| 1169 |
|
| 1170 |
if( aStatus.isValid(osl_FileStatus_Mask_Type) && |
| 1171 |
aStatus.isValid(osl_FileStatus_Mask_LinkTargetURL) && |
| 1172 |
aStatus.getFileType() == osl::FileStatus::Link ) |
| 1173 |
targetPath = aStatus.getLinkTargetURL(); |
| 1174 |
|
| 1175 |
// Will do nothing if file does not exist. |
| 1176 |
osl::File::remove( targetPath ); |
| 1177 |
|
| 1178 |
nError = osl_File_move( srcUnqPath,targetPath ); |
| 1179 |
if( nError != osl::FileBase::E_None ) |
| 1180 |
{ |
| 1181 |
installError( CommandId, |
| 1182 |
TaskHandlerErr::OVERWRITE_FOR_MOVE, |
| 1183 |
nError ); |
| 1184 |
return; |
| 1185 |
} |
| 1186 |
break; |
| 1187 |
} |
| 1188 |
case NameClash::RENAME: |
| 1189 |
{ |
| 1190 |
OUString newDstUnqPath; |
| 1191 |
nError = osl_File_move( srcUnqPath,dstUnqPath,true ); |
| 1192 |
if( nError == osl::FileBase::E_EXIST ) |
| 1193 |
{ |
| 1194 |
// "invent" a new valid title. |
| 1195 |
|
| 1196 |
sal_Int32 nPos = -1; |
| 1197 |
sal_Int32 nLastDot = dstUnqPath.lastIndexOf( '.' ); |
| 1198 |
sal_Int32 nLastSlash = dstUnqPath.lastIndexOf( '/' ); |
| 1199 |
if( ( nLastSlash < nLastDot ) // dot is part of last(!) path segment |
| 1200 |
&& ( nLastSlash != ( nLastDot - 1 ) ) ) // file name does not start with a dot |
| 1201 |
nPos = nLastDot; |
| 1202 |
else |
| 1203 |
nPos = dstUnqPath.getLength(); |
| 1204 |
|
| 1205 |
sal_Int32 nTry = 0; |
| 1206 |
|
| 1207 |
do |
| 1208 |
{ |
| 1209 |
newDstUnqPath = dstUnqPath; |
| 1210 |
|
| 1211 |
OUString aPostfix = "_" + OUString::number( ++nTry ); |
| 1212 |
|
| 1213 |
newDstUnqPath = newDstUnqPath.replaceAt( nPos, 0, aPostfix ); |
| 1214 |
|
| 1215 |
nError = osl_File_move( srcUnqPath,newDstUnqPath,true ); |
| 1216 |
} |
| 1217 |
while( ( nError == osl::FileBase::E_EXIST ) && ( nTry < 10000 ) ); |
| 1218 |
} |
| 1219 |
|
| 1220 |
if( nError == osl::FileBase::E_EXIST ) |
| 1221 |
{ |
| 1222 |
installError( CommandId, |
| 1223 |
TaskHandlerErr::RENAME_FOR_MOVE ); |
| 1224 |
return; |
| 1225 |
} |
| 1226 |
else if( nError != osl::FileBase::E_None ) |
| 1227 |
{ |
| 1228 |
installError( CommandId, |
| 1229 |
TaskHandlerErr::RENAMEMOVE_FOR_MOVE, |
| 1230 |
nError ); |
| 1231 |
return; |
| 1232 |
} |
| 1233 |
else |
| 1234 |
dstUnqPath = newDstUnqPath; |
| 1235 |
|
| 1236 |
break; |
| 1237 |
} |
| 1238 |
case NameClash::ERROR: |
| 1239 |
{ |
| 1240 |
nError = osl_File_move( srcUnqPath,dstUnqPath,true ); |
| 1241 |
if( nError == osl::FileBase::E_EXIST ) |
| 1242 |
{ |
| 1243 |
installError( CommandId, |
| 1244 |
TaskHandlerErr::NAMECLASH_FOR_MOVE ); |
| 1245 |
return; |
| 1246 |
} |
| 1247 |
else if( nError != osl::FileBase::E_None ) |
| 1248 |
{ |
| 1249 |
installError( CommandId, |
| 1250 |
TaskHandlerErr::NAMECLASHMOVE_FOR_MOVE, |
| 1251 |
nError ); |
| 1252 |
return; |
| 1253 |
} |
| 1254 |
break; |
| 1255 |
} |
| 1256 |
case NameClash::ASK: |
| 1257 |
default: |
| 1258 |
{ |
| 1259 |
nError = osl_File_move( srcUnqPath,dstUnqPath,true ); |
| 1260 |
if( nError == osl::FileBase::E_EXIST ) |
| 1261 |
{ |
| 1262 |
installError( CommandId, |
| 1263 |
TaskHandlerErr::NAMECLASHSUPPORT_FOR_MOVE, |
| 1264 |
NameClash::ASK); |
| 1265 |
return; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
break; |
| 1269 |
} |
| 1270 |
|
| 1271 |
// Determine, whether we have moved a file or a folder |
| 1272 |
osl::DirectoryItem aItem; |
| 1273 |
nError = osl::DirectoryItem::get( dstUnqPath,aItem ); |
| 1274 |
if( nError != osl::FileBase::E_None ) |
| 1275 |
{ |
| 1276 |
installError( CommandId, |
| 1277 |
TaskHandlerErr::TRANSFER_BY_MOVE_SOURCE, |
| 1278 |
nError ); |
| 1279 |
return; |
| 1280 |
} |
| 1281 |
osl::FileStatus aStatus( osl_FileStatus_Mask_Type ); |
| 1282 |
nError = aItem.getFileStatus( aStatus ); |
| 1283 |
if( nError != osl::FileBase::E_None || ! aStatus.isValid( osl_FileStatus_Mask_Type ) ) |
| 1284 |
{ |
| 1285 |
installError( CommandId, |
| 1286 |
TaskHandlerErr::TRANSFER_BY_MOVE_SOURCESTAT, |
| 1287 |
nError ); |
| 1288 |
return; |
| 1289 |
} |
| 1290 |
bool isDocument = ( aStatus.getFileType() == osl::FileStatus::Regular ); |
| 1291 |
|
| 1292 |
|
| 1293 |
copyPersistentSet( srcUnqPath,dstUnqPath,!isDocument ); |
| 1294 |
|
| 1295 |
OUString aDstParent = getParentName( dstUnqPath ); |
| 1296 |
OUString aSrcParent = getParentName( srcUnqPath ); |
| 1297 |
|
| 1298 |
notifyInsert( getContentEventListeners( aDstParent ),dstUnqPath ); |
| 1299 |
if( aDstParent != aSrcParent ) |
| 1300 |
notifyContentRemoved( getContentEventListeners( aSrcParent ),srcUnqPath ); |
| 1301 |
|
| 1302 |
notifyContentExchanged( getContentExchangedEventListeners( srcUnqPath,dstUnqPath,!isDocument ) ); |
| 1303 |
erasePersistentSet( srcUnqPath,!isDocument ); |
| 1304 |
} |
| 1305 |
|
| 1306 |
|
| 1307 |
/********************************************************************************/ |
| 1308 |
/* */ |
| 1309 |
/* copy-implementation */ |
| 1310 |
/* */ |
| 1311 |
/********************************************************************************/ |
| 1312 |
|
| 1313 |
// Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories ) |
| 1314 |
|
| 1315 |
|
| 1316 |
namespace { |
| 1317 |
|
| 1318 |
bool getType( |
| 1319 |
TaskManager & task, sal_Int32 id, OUString const & fileUrl, |
| 1320 |
osl::DirectoryItem * item, osl::FileStatus::Type * type) |
| 1321 |
{ |
| 1322 |
assert(item != nullptr && type != nullptr); |
| 1323 |
osl::FileBase::RC err = osl::DirectoryItem::get(fileUrl, *item); |
| 1324 |
if (err != osl::FileBase::E_None) { |
| 1325 |
task.installError(id, TaskHandlerErr::TRANSFER_BY_COPY_SOURCE, err); |
| 1326 |
return false; |
| 1327 |
} |
| 1328 |
osl::FileStatus stat(osl_FileStatus_Mask_Type); |
| 1329 |
err = item->getFileStatus(stat); |
| 1330 |
if (err != osl::FileBase::E_None) { |
| 1331 |
task.installError(id, TaskHandlerErr::TRANSFER_BY_COPY_SOURCESTAT, err); |
| 1332 |
return false; |
| 1333 |
} |
| 1334 |
*type = stat.getFileType(); |
| 1335 |
return true; |
| 1336 |
} |
| 1337 |
|
| 1338 |
} |
| 1339 |
|
| 1340 |
void |
| 1341 |
TaskManager::copy( |
| 1342 |
sal_Int32 CommandId, |
| 1343 |
const OUString& srcUnqPath, |
| 1344 |
const OUString& dstUnqPathIn, |
| 1345 |
sal_Int32 NameClash ) |
| 1346 |
{ |
| 1347 |
osl::FileBase::RC nError; |
| 1348 |
OUString dstUnqPath( dstUnqPathIn ); |
| 1349 |
|
| 1350 |
// Resolve symbolic links within the source path. If srcUnqPath denotes a |
| 1351 |
// symbolic link (targeting either a file or a folder), the contents of the |
| 1352 |
// target is copied (recursively, in the case of a folder). However, if |
| 1353 |
// recursively copying the contents of a folder causes a symbolic link to be |
| 1354 |
// copied, the symbolic link itself is copied. |
| 1355 |
osl::DirectoryItem item; |
| 1356 |
osl::FileStatus::Type type; |
| 1357 |
if (!getType(*this, CommandId, srcUnqPath, &item, &type)) { |
| 1358 |
return; |
| 1359 |
} |
| 1360 |
OUString rslvdSrcUnqPath; |
| 1361 |
if (type == osl::FileStatus::Link) { |
| 1362 |
osl::FileStatus stat(osl_FileStatus_Mask_LinkTargetURL); |
| 1363 |
nError = item.getFileStatus(stat); |
| 1364 |
if (nError != osl::FileBase::E_None) { |
| 1365 |
installError( |
| 1366 |
CommandId, TaskHandlerErr::TRANSFER_BY_COPY_SOURCESTAT, nError); |
| 1367 |
return; |
| 1368 |
} |
| 1369 |
rslvdSrcUnqPath = stat.getLinkTargetURL(); |
| 1370 |
if (!getType(*this, CommandId, srcUnqPath, &item, &type)) { |
| 1371 |
return; |
| 1372 |
} |
| 1373 |
} else { |
| 1374 |
rslvdSrcUnqPath = srcUnqPath; |
| 1375 |
} |
| 1376 |
|
| 1377 |
bool isDocument |
| 1378 |
= type != osl::FileStatus::Directory && type != osl::FileStatus::Volume; |
| 1379 |
FileUrlType IsWhat = isDocument ? FileUrlType::File : FileUrlType::Folder; |
| 1380 |
|
| 1381 |
switch( NameClash ) |
| 1382 |
{ |
| 1383 |
case NameClash::KEEP: |
| 1384 |
{ |
| 1385 |
nError = copy_recursive( rslvdSrcUnqPath,dstUnqPath,IsWhat,true ); |
| 1386 |
if( nError != osl::FileBase::E_None && nError != osl::FileBase::E_EXIST ) |
| 1387 |
{ |
| 1388 |
installError( CommandId, |
| 1389 |
TaskHandlerErr::KEEPERROR_FOR_COPY, |
| 1390 |
nError ); |
| 1391 |
return; |
| 1392 |
} |
| 1393 |
break; |
| 1394 |
} |
| 1395 |
case NameClash::OVERWRITE: |
| 1396 |
{ |
| 1397 |
// remove (..., MustExist = sal_False). |
| 1398 |
remove( CommandId, dstUnqPath, IsWhat, false ); |
| 1399 |
|
| 1400 |
// copy. |
| 1401 |
nError = copy_recursive( rslvdSrcUnqPath,dstUnqPath,IsWhat,false ); |
| 1402 |
if( nError != osl::FileBase::E_None ) |
| 1403 |
{ |
| 1404 |
installError( CommandId, |
| 1405 |
TaskHandlerErr::OVERWRITE_FOR_COPY, |
| 1406 |
nError ); |
| 1407 |
return; |
| 1408 |
} |
| 1409 |
break; |
| 1410 |
} |
| 1411 |
case NameClash::RENAME: |
| 1412 |
{ |
| 1413 |
OUString newDstUnqPath = dstUnqPath; |
| 1414 |
nError = copy_recursive( rslvdSrcUnqPath,dstUnqPath,IsWhat,true ); |
| 1415 |
|
| 1416 |
if( nError == osl::FileBase::E_EXIST ) |
| 1417 |
{ |
| 1418 |
// "invent" a new valid title. |
| 1419 |
|
| 1420 |
sal_Int32 nPos = -1; |
| 1421 |
sal_Int32 nLastDot = dstUnqPath.lastIndexOf( '.' ); |
| 1422 |
sal_Int32 nLastSlash = dstUnqPath.lastIndexOf( '/' ); |
| 1423 |
if ( ( nLastSlash < nLastDot ) // dot is part of last(!) path segment |
| 1424 |
&& ( nLastSlash != ( nLastDot - 1 ) ) ) // file name does not start with a dot |
| 1425 |
nPos = nLastDot; |
| 1426 |
else |
| 1427 |
nPos = dstUnqPath.getLength(); |
| 1428 |
|
| 1429 |
sal_Int32 nTry = 0; |
| 1430 |
|
| 1431 |
do |
| 1432 |
{ |
| 1433 |
newDstUnqPath = dstUnqPath; |
| 1434 |
|
| 1435 |
OUString aPostfix = "_" + OUString::number( ++nTry ); |
| 1436 |
|
| 1437 |
newDstUnqPath = newDstUnqPath.replaceAt( nPos, 0, aPostfix ); |
| 1438 |
|
| 1439 |
nError = copy_recursive( rslvdSrcUnqPath,newDstUnqPath,IsWhat,true ); |
| 1440 |
} |
| 1441 |
while( ( nError == osl::FileBase::E_EXIST ) && ( nTry < 10000 ) ); |
| 1442 |
} |
| 1443 |
|
| 1444 |
if( nError == osl::FileBase::E_EXIST ) |
| 1445 |
{ |
| 1446 |
installError( CommandId, |
| 1447 |
TaskHandlerErr::RENAME_FOR_COPY ); |
| 1448 |
return; |
| 1449 |
} |
| 1450 |
else if( nError != osl::FileBase::E_None ) |
| 1451 |
{ |
| 1452 |
installError( CommandId, |
| 1453 |
TaskHandlerErr::RENAMEMOVE_FOR_COPY, |
| 1454 |
nError ); |
| 1455 |
return; |
| 1456 |
} |
| 1457 |
else |
| 1458 |
dstUnqPath = newDstUnqPath; |
| 1459 |
|
| 1460 |
break; |
| 1461 |
} |
| 1462 |
case NameClash::ERROR: |
| 1463 |
{ |
| 1464 |
nError = copy_recursive( rslvdSrcUnqPath,dstUnqPath,IsWhat,true ); |
| 1465 |
|
| 1466 |
if( nError == osl::FileBase::E_EXIST ) |
| 1467 |
{ |
| 1468 |
installError( CommandId, |
| 1469 |
TaskHandlerErr::NAMECLASH_FOR_COPY ); |
| 1470 |
return; |
| 1471 |
} |
| 1472 |
else if( nError != osl::FileBase::E_None ) |
| 1473 |
{ |
| 1474 |
installError( CommandId, |
| 1475 |
TaskHandlerErr::NAMECLASHMOVE_FOR_COPY, |
| 1476 |
nError ); |
| 1477 |
return; |
| 1478 |
} |
| 1479 |
break; |
| 1480 |
} |
| 1481 |
case NameClash::ASK: |
| 1482 |
default: |
| 1483 |
{ |
| 1484 |
nError = copy_recursive( rslvdSrcUnqPath,dstUnqPath,IsWhat,true ); |
| 1485 |
|
| 1486 |
if( nError == osl::FileBase::E_EXIST ) |
| 1487 |
{ |
| 1488 |
installError( CommandId, |
| 1489 |
TaskHandlerErr::NAMECLASHSUPPORT_FOR_COPY, |
| 1490 |
NameClash); |
| 1491 |
return; |
| 1492 |
} |
| 1493 |
break; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
copyPersistentSet( srcUnqPath,dstUnqPath, !isDocument ); |
| 1498 |
notifyInsert( getContentEventListeners( getParentName( dstUnqPath ) ),dstUnqPath ); |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
/********************************************************************************/ |
| 1503 |
/* */ |
| 1504 |
/* remove-implementation */ |
| 1505 |
/* */ |
| 1506 |
/********************************************************************************/ |
| 1507 |
|
| 1508 |
// Deletes the content belonging to fileURL aUnqPath( recursively in case of directory ) |
| 1509 |
// Return: success of operation |
| 1510 |
|
| 1511 |
|
| 1512 |
bool |
| 1513 |
TaskManager::remove( sal_Int32 CommandId, |
| 1514 |
const OUString& aUnqPath, |
| 1515 |
FileUrlType IsWhat, |
| 1516 |
bool MustExist ) |
| 1517 |
{ |
| 1518 |
sal_Int32 nMask = osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileURL; |
| 1519 |
|
| 1520 |
osl::DirectoryItem aItem; |
| 1521 |
osl::FileStatus aStatus( nMask ); |
| 1522 |
osl::FileBase::RC nError; |
| 1523 |
|
| 1524 |
if( IsWhat == FileUrlType::Unknown ) // Determine whether we are removing a directory or a file |
| 1525 |
{ |
| 1526 |
nError = osl::DirectoryItem::get( aUnqPath, aItem ); |
| 1527 |
if( nError != osl::FileBase::E_None ) |
| 1528 |
{ |
| 1529 |
if (MustExist) |
| 1530 |
{ |
| 1531 |
installError( CommandId, |
| 1532 |
TaskHandlerErr::NOSUCHFILEORDIR_FOR_REMOVE, |
| 1533 |
nError ); |
| 1534 |
} |
| 1535 |
return (!MustExist); |
| 1536 |
} |
| 1537 |
|
| 1538 |
nError = aItem.getFileStatus( aStatus ); |
| 1539 |
if( nError != osl::FileBase::E_None || ! aStatus.isValid( nMask ) ) |
| 1540 |
{ |
| 1541 |
installError( CommandId, |
| 1542 |
TaskHandlerErr::VALIDFILESTATUS_FOR_REMOVE, |
| 1543 |
nError != osl::FileBase::E_None ? nError : 0 ); |
| 1544 |
return false; |
| 1545 |
} |
| 1546 |
|
| 1547 |
if( aStatus.getFileType() == osl::FileStatus::Regular || |
| 1548 |
aStatus.getFileType() == osl::FileStatus::Link ) |
| 1549 |
IsWhat = FileUrlType::File; |
| 1550 |
else if( aStatus.getFileType() == osl::FileStatus::Directory || |
| 1551 |
aStatus.getFileType() == osl::FileStatus::Volume ) |
| 1552 |
IsWhat = FileUrlType::Folder; |
| 1553 |
} |
| 1554 |
|
| 1555 |
|
| 1556 |
if( IsWhat == FileUrlType::File ) |
| 1557 |
{ |
| 1558 |
nError = osl::File::remove( aUnqPath ); |
| 1559 |
if( nError != osl::FileBase::E_None ) |
| 1560 |
{ |
| 1561 |
if (MustExist) |
| 1562 |
{ |
| 1563 |
installError( CommandId, |
| 1564 |
TaskHandlerErr::DELETEFILE_FOR_REMOVE, |
| 1565 |
nError ); |
| 1566 |
} |
| 1567 |
return (!MustExist); |
| 1568 |
} |
| 1569 |
else |
| 1570 |
{ |
| 1571 |
notifyContentDeleted( getContentDeletedEventListeners(aUnqPath) ); |
| 1572 |
erasePersistentSet( aUnqPath ); // Removes from XPersistentPropertySet |
| 1573 |
} |
| 1574 |
} |
| 1575 |
else if( IsWhat == FileUrlType::Folder ) |
| 1576 |
{ |
| 1577 |
osl::Directory aDirectory( aUnqPath ); |
| 1578 |
|
| 1579 |
nError = aDirectory.open(); |
| 1580 |
if( nError != osl::FileBase::E_None ) |
| 1581 |
{ |
| 1582 |
if (MustExist) |
| 1583 |
{ |
| 1584 |
installError( CommandId, |
| 1585 |
TaskHandlerErr::OPENDIRECTORY_FOR_REMOVE, |
| 1586 |
nError ); |
| 1587 |
} |
| 1588 |
return (!MustExist); |
| 1589 |
} |
| 1590 |
|
| 1591 |
bool whileSuccess = true; |
| 1592 |
FileUrlType recurse = FileUrlType::Unknown; |
| 1593 |
OUString name; |
| 1594 |
|
| 1595 |
nError = aDirectory.getNextItem( aItem ); |
| 1596 |
while( nError == osl::FileBase::E_None ) |
| 1597 |
{ |
| 1598 |
nError = aItem.getFileStatus( aStatus ); |
| 1599 |
if( nError != osl::FileBase::E_None || ! aStatus.isValid( nMask ) ) |
| 1600 |
{ |
| 1601 |
installError( CommandId, |
| 1602 |
TaskHandlerErr::VALIDFILESTATUSWHILE_FOR_REMOVE, |
| 1603 |
nError != osl::FileBase::E_None ? nError : 0 ); |
| 1604 |
whileSuccess = false; |
| 1605 |
break; |
| 1606 |
} |
| 1607 |
|
| 1608 |
if( aStatus.getFileType() == osl::FileStatus::Regular || |
| 1609 |
aStatus.getFileType() == osl::FileStatus::Link ) |
| 1610 |
recurse = FileUrlType::File; |
| 1611 |
else if( aStatus.getFileType() == osl::FileStatus::Directory || |
| 1612 |
aStatus.getFileType() == osl::FileStatus::Volume ) |
| 1613 |
recurse = FileUrlType::Folder; |
| 1614 |
|
| 1615 |
name = aStatus.getFileURL(); |
| 1616 |
whileSuccess = remove( CommandId, name, recurse, MustExist ); |
| 1617 |
if( !whileSuccess ) |
| 1618 |
break; |
| 1619 |
|
| 1620 |
nError = aDirectory.getNextItem( aItem ); |
| 1621 |
} |
| 1622 |
|
| 1623 |
aDirectory.close(); |
| 1624 |
|
| 1625 |
if( ! whileSuccess ) |
| 1626 |
return false; // error code is installed |
| 1627 |
|
| 1628 |
if( nError != osl::FileBase::E_NOENT ) |
| 1629 |
{ |
| 1630 |
installError( CommandId, |
| 1631 |
TaskHandlerErr::DIRECTORYEXHAUSTED_FOR_REMOVE, |
| 1632 |
nError ); |
| 1633 |
return false; |
| 1634 |
} |
| 1635 |
|
| 1636 |
nError = osl::Directory::remove( aUnqPath ); |
| 1637 |
if( nError != osl::FileBase::E_None ) |
| 1638 |
{ |
| 1639 |
if (MustExist) |
| 1640 |
{ |
| 1641 |
installError( CommandId, |
| 1642 |
TaskHandlerErr::DELETEDIRECTORY_FOR_REMOVE, |
| 1643 |
nError ); |
| 1644 |
} |
| 1645 |
return (!MustExist); |
| 1646 |
} |
| 1647 |
else |
| 1648 |
{ |
| 1649 |
notifyContentDeleted( getContentDeletedEventListeners(aUnqPath) ); |
| 1650 |
erasePersistentSet( aUnqPath ); |
| 1651 |
} |
| 1652 |
} |
| 1653 |
else // Don't know what to remove |
| 1654 |
{ |
| 1655 |
installError( CommandId, |
| 1656 |
TaskHandlerErr::FILETYPE_FOR_REMOVE ); |
| 1657 |
return false; |
| 1658 |
} |
| 1659 |
|
| 1660 |
return true; |
| 1661 |
} |
| 1662 |
|
| 1663 |
|
| 1664 |
/********************************************************************************/ |
| 1665 |
/* */ |
| 1666 |
/* mkdir-implementation */ |
| 1667 |
/* */ |
| 1668 |
/********************************************************************************/ |
| 1669 |
|
| 1670 |
// Creates new directory with given URL, recursively if necessary |
| 1671 |
// Return:: success of operation |
| 1672 |
|
| 1673 |
|
| 1674 |
bool |
| 1675 |
TaskManager::mkdir( sal_Int32 CommandId, |
| 1676 |
const OUString& rUnqPath, |
| 1677 |
bool OverWrite ) |
| 1678 |
{ |
| 1679 |
OUString aUnqPath; |
| 1680 |
|
| 1681 |
// remove trailing slash |
| 1682 |
if ( rUnqPath.endsWith("/") ) |
| 1683 |
aUnqPath = rUnqPath.copy( 0, rUnqPath.getLength() - 1 ); |
| 1684 |
else |
| 1685 |
aUnqPath = rUnqPath; |
| 1686 |
|
| 1687 |
osl::FileBase::RC nError = osl::Directory::create( aUnqPath ); |
| 1688 |
|
| 1689 |
switch ( nError ) |
| 1690 |
{ |
| 1691 |
case osl::FileBase::E_EXIST: // Directory cannot be overwritten |
| 1692 |
{ |
| 1693 |
if( !OverWrite ) |
| 1694 |
{ |
| 1695 |
installError( CommandId, |
| 1696 |
TaskHandlerErr::FOLDER_EXISTS_MKDIR ); |
| 1697 |
return false; |
| 1698 |
} |
| 1699 |
else |
| 1700 |
return true; |
| 1701 |
} |
| 1702 |
case osl::FileBase::E_INVAL: |
| 1703 |
{ |
| 1704 |
installError(CommandId, |
| 1705 |
TaskHandlerErr::INVALID_NAME_MKDIR); |
| 1706 |
return false; |
| 1707 |
} |
| 1708 |
case osl::FileBase::E_None: |
| 1709 |
{ |
| 1710 |
OUString aPrtPath = getParentName( aUnqPath ); |
| 1711 |
notifyInsert( getContentEventListeners( aPrtPath ),aUnqPath ); |
| 1712 |
return true; |
| 1713 |
} |
| 1714 |
default: |
| 1715 |
return ensuredir( |
| 1716 |
CommandId, |
| 1717 |
aUnqPath, |
| 1718 |
TaskHandlerErr::CREATEDIRECTORY_MKDIR ); |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
/********************************************************************************/ |
| 1724 |
/* */ |
| 1725 |
/* mkfil-implementation */ |
| 1726 |
/* */ |
| 1727 |
/********************************************************************************/ |
| 1728 |
|
| 1729 |
// Creates new file with given URL. |
| 1730 |
// The content of aInputStream becomes the content of the file |
| 1731 |
// Return:: success of operation |
| 1732 |
|
| 1733 |
|
| 1734 |
bool |
| 1735 |
TaskManager::mkfil( sal_Int32 CommandId, |
| 1736 |
const OUString& aUnqPath, |
| 1737 |
bool Overwrite, |
| 1738 |
const uno::Reference< io::XInputStream >& aInputStream ) |
| 1739 |
{ |
| 1740 |
// return value unimportant |
| 1741 |
bool bSuccess = write( CommandId, |
| 1742 |
aUnqPath, |
| 1743 |
Overwrite, |
| 1744 |
aInputStream ); |
| 1745 |
if ( bSuccess ) |
| 1746 |
{ |
| 1747 |
OUString aPrtPath = getParentName( aUnqPath ); |
| 1748 |
notifyInsert( getContentEventListeners( aPrtPath ),aUnqPath ); |
| 1749 |
} |
| 1750 |
return bSuccess; |
| 1751 |
} |
| 1752 |
|
| 1753 |
|
| 1754 |
/********************************************************************************/ |
| 1755 |
/* */ |
| 1756 |
/* write-implementation */ |
| 1757 |
/* */ |
| 1758 |
/********************************************************************************/ |
| 1759 |
|
| 1760 |
// writes to the file with given URL. |
| 1761 |
// The content of aInputStream becomes the content of the file |
| 1762 |
// Return:: success of operation |
| 1763 |
|
| 1764 |
|
| 1765 |
bool |
| 1766 |
TaskManager::write( sal_Int32 CommandId, |
| 1767 |
const OUString& aUnqPath, |
| 1768 |
bool OverWrite, |
| 1769 |
const uno::Reference< io::XInputStream >& aInputStream ) |
| 1770 |
{ |
| 1771 |
if( ! aInputStream.is() ) |
| 1772 |
{ |
| 1773 |
installError( CommandId, |
| 1774 |
TaskHandlerErr::INPUTSTREAM_FOR_WRITE ); |
| 1775 |
return false; |
| 1776 |
} |
| 1777 |
|
| 1778 |
// Create parent path, if necessary. |
| 1779 |
if ( ! ensuredir( CommandId, |
| 1780 |
getParentName( aUnqPath ), |
| 1781 |
TaskHandlerErr::ENSUREDIR_FOR_WRITE ) ) |
| 1782 |
return false; |
| 1783 |
|
| 1784 |
osl::FileBase::RC err; |
| 1785 |
osl::File aFile( aUnqPath ); |
| 1786 |
|
| 1787 |
if( OverWrite ) |
| 1788 |
{ |
| 1789 |
err = aFile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ); |
| 1790 |
|
| 1791 |
if( err != osl::FileBase::E_None ) |
| 1792 |
{ |
| 1793 |
aFile.close(); |
| 1794 |
err = aFile.open( osl_File_OpenFlag_Write ); |
| 1795 |
|
| 1796 |
if( err != osl::FileBase::E_None ) |
| 1797 |
{ |
| 1798 |
installError( CommandId, |
| 1799 |
TaskHandlerErr::NO_OPEN_FILE_FOR_OVERWRITE, |
| 1800 |
err ); |
| 1801 |
return false; |
| 1802 |
} |
| 1803 |
|
| 1804 |
// the existing file was just opened and should be overwritten now, |
| 1805 |
// truncate it first |
| 1806 |
|
| 1807 |
err = aFile.setSize( 0 ); |
| 1808 |
if( err != osl::FileBase::E_None ) |
| 1809 |
{ |
| 1810 |
installError( CommandId, |
| 1811 |
TaskHandlerErr::FILESIZE_FOR_WRITE, |
| 1812 |
err ); |
| 1813 |
return false; |
| 1814 |
} |
| 1815 |
} |
| 1816 |
} |
| 1817 |
else |
| 1818 |
{ |
| 1819 |
err = aFile.open( osl_File_OpenFlag_Read | osl_File_OpenFlag_NoLock ); |
| 1820 |
if( err == osl::FileBase::E_None ) // The file exists and shall not be overwritten |
| 1821 |
{ |
| 1822 |
installError( CommandId, |
| 1823 |
TaskHandlerErr::NOREPLACE_FOR_WRITE, // Now an exception |
| 1824 |
err ); |
| 1825 |
|
| 1826 |
aFile.close(); |
| 1827 |
return false; |
| 1828 |
} |
| 1829 |
|
| 1830 |
// as a temporary solution the creation does not lock the file at all |
| 1831 |
// in future it should be possible to create the file without lock explicitly |
| 1832 |
err = aFile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create | osl_File_OpenFlag_NoLock ); |
| 1833 |
|
| 1834 |
if( err != osl::FileBase::E_None ) |
| 1835 |
{ |
| 1836 |
aFile.close(); |
| 1837 |
installError( CommandId, |
| 1838 |
TaskHandlerErr::NO_OPEN_FILE_FOR_WRITE, |
| 1839 |
err ); |
| 1840 |
return false; |
| 1841 |
} |
| 1842 |
} |
| 1843 |
|
| 1844 |
bool bSuccess = true; |
| 1845 |
|
| 1846 |
sal_uInt64 nWrittenBytes; |
| 1847 |
sal_Int32 nReadBytes = 0, nRequestedBytes = 32768 /*32k*/; |
| 1848 |
uno::Sequence< sal_Int8 > seq( nRequestedBytes ); |
| 1849 |
|
| 1850 |
do |
| 1851 |
{ |
| 1852 |
try |
| 1853 |
{ |
| 1854 |
nReadBytes = aInputStream->readBytes( seq, |
| 1855 |
nRequestedBytes ); |
| 1856 |
} |
| 1857 |
catch( const io::NotConnectedException& ) |
| 1858 |
{ |
| 1859 |
installError( CommandId, |
| 1860 |
TaskHandlerErr::NOTCONNECTED_FOR_WRITE ); |
| 1861 |
bSuccess = false; |
| 1862 |
break; |
| 1863 |
} |
| 1864 |
catch( const io::BufferSizeExceededException& ) |
| 1865 |
{ |
| 1866 |
installError( CommandId, |
| 1867 |
TaskHandlerErr::BUFFERSIZEEXCEEDED_FOR_WRITE ); |
| 1868 |
bSuccess = false; |
| 1869 |
break; |
| 1870 |
} |
| 1871 |
catch( const io::IOException& ) |
| 1872 |
{ |
| 1873 |
installError( CommandId, |
| 1874 |
TaskHandlerErr::IOEXCEPTION_FOR_WRITE ); |
| 1875 |
bSuccess = false; |
| 1876 |
break; |
| 1877 |
} |
| 1878 |
|
| 1879 |
if( nReadBytes ) |
| 1880 |
{ |
| 1881 |
const sal_Int8* p = seq.getConstArray(); |
| 1882 |
|
| 1883 |
err = aFile.write( static_cast<void const *>(p), |
| 1884 |
sal_uInt64( nReadBytes ), |
| 1885 |
nWrittenBytes ); |
| 1886 |
|
| 1887 |
if( err != osl::FileBase::E_None ) |
| 1888 |
{ |
| 1889 |
installError( CommandId, |
| 1890 |
TaskHandlerErr::FILEIOERROR_FOR_WRITE, |
| 1891 |
err ); |
| 1892 |
bSuccess = false; |
| 1893 |
break; |
| 1894 |
} |
| 1895 |
else if( nWrittenBytes != sal_uInt64( nReadBytes ) ) |
| 1896 |
{ |
| 1897 |
installError( CommandId, |
| 1898 |
TaskHandlerErr::FILEIOERROR_FOR_NO_SPACE ); |
| 1899 |
bSuccess = false; |
| 1900 |
break; |
| 1901 |
} |
| 1902 |
} |
| 1903 |
} while( nReadBytes == nRequestedBytes ); |
| 1904 |
|
| 1905 |
err = aFile.close(); |
| 1906 |
if( err != osl::FileBase::E_None ) |
| 1907 |
{ |
| 1908 |
installError( CommandId, |
| 1909 |
TaskHandlerErr::FILEIOERROR_FOR_WRITE, |
| 1910 |
err ); |
| 1911 |
bSuccess = false; |
| 1912 |
} |
| 1913 |
|
| 1914 |
return bSuccess; |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
/*********************************************************************************/ |
| 1919 |
/* */ |
| 1920 |
/* insertDefaultProperties-Implementation */ |
| 1921 |
/* */ |
| 1922 |
/*********************************************************************************/ |
| 1923 |
|
| 1924 |
|
| 1925 |
void TaskManager::insertDefaultProperties( const OUString& aUnqPath ) |
| 1926 |
{ |
| 1927 |
std::unique_lock aGuard(m_aMutex); |
| 1928 |
insertDefaultProperties(aGuard, aUnqPath); |
| 1929 |
} |
| 1930 |
|
| 1931 |
void TaskManager::insertDefaultProperties( std::unique_lock<std::mutex>& /*rGuard*/, const OUString& aUnqPath ) |
| 1932 |
{ |
| 1933 |
ContentMap::iterator it = |
| 1934 |
m_aContent.emplace( aUnqPath,UnqPathData() ).first; |
| 1935 |
|
| 1936 |
load( it, false ); |
| 1937 |
|
| 1938 |
MyProperty ContentTProperty( ContentType ); |
| 1939 |
|
| 1940 |
PropertySet& properties = it->second.properties; |
| 1941 |
bool ContentNotDefau = properties.find( ContentTProperty ) != properties.end(); |
| 1942 |
|
| 1943 |
properties.reserve(properties.size() + m_aDefaultProperties.size()); |
| 1944 |
for (auto const& defaultprop : m_aDefaultProperties) |
| 1945 |
{ |
| 1946 |
if( !ContentNotDefau || defaultprop.getPropertyName() != ContentType ) |
| 1947 |
properties.insert( defaultprop ); |
| 1948 |
} |
| 1949 |
} |
| 1950 |
|
| 1951 |
|
| 1952 |
/******************************************************************************/ |
| 1953 |
/* */ |
| 1954 |
/* mapping of file urls */ |
| 1955 |
/* to uncpath and vice versa */ |
| 1956 |
/* */ |
| 1957 |
/******************************************************************************/ |
| 1958 |
|
| 1959 |
|
| 1960 |
bool TaskManager::getUnqFromUrl( const OUString& Url, OUString& Unq ) |
| 1961 |
{ |
| 1962 |
if ( Url == "file:///" || Url == "file://localhost/" || Url == "file://127.0.0.1/" ) |
| 1963 |
{ |
| 1964 |
Unq = "file:///"; |
| 1965 |
return false; |
| 1966 |
} |
| 1967 |
|
| 1968 |
bool err = osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( Url,Unq ); |
| 1969 |
|
| 1970 |
Unq = Url; |
| 1971 |
|
| 1972 |
sal_Int32 l = Unq.getLength()-1; |
| 1973 |
if( ! err && Unq.endsWith("/") && |
| 1974 |
Unq.indexOf( '/', RTL_CONSTASCII_LENGTH("//") ) != -1 ) |
| 1975 |
Unq = Unq.copy(0, l); |
| 1976 |
|
| 1977 |
return err; |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
bool TaskManager::getUrlFromUnq( const OUString& Unq,OUString& Url ) |
| 1982 |
{ |
| 1983 |
bool err = osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( Unq,Url ); |
| 1984 |
|
| 1985 |
Url = Unq; |
| 1986 |
|
| 1987 |
return err; |
| 1988 |
} |
| 1989 |
|
| 1990 |
|
| 1991 |
// Helper function for public copy |
| 1992 |
|
| 1993 |
osl::FileBase::RC |
| 1994 |
TaskManager::copy_recursive( const OUString& srcUnqPath, |
| 1995 |
const OUString& dstUnqPath, |
| 1996 |
FileUrlType TypeToCopy, |
| 1997 |
bool testExistBeforeCopy ) |
| 1998 |
{ |
| 1999 |
osl::FileBase::RC err = osl::FileBase::E_None; |
| 2000 |
|
| 2001 |
if( TypeToCopy == FileUrlType::File ) // Document |
| 2002 |
{ |
| 2003 |
err = osl_File_copy( srcUnqPath,dstUnqPath,testExistBeforeCopy ); |
| 2004 |
} |
| 2005 |
else if( TypeToCopy == FileUrlType::Folder ) |
| 2006 |
{ |
| 2007 |
osl::Directory aDir( srcUnqPath ); |
| 2008 |
(void)aDir.open(); |
| 2009 |
|
| 2010 |
err = osl::Directory::create( dstUnqPath ); |
| 2011 |
osl::FileBase::RC next = err; |
| 2012 |
if( err == osl::FileBase::E_None ) |
| 2013 |
{ |
| 2014 |
sal_Int32 const n_Mask = osl_FileStatus_Mask_FileURL | osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type; |
| 2015 |
|
| 2016 |
osl::DirectoryItem aDirItem; |
| 2017 |
|
| 2018 |
while( err == osl::FileBase::E_None ) |
| 2019 |
{ |
| 2020 |
next = aDir.getNextItem( aDirItem ); |
| 2021 |
if (next != osl::FileBase::E_None ) |
| 2022 |
break; |
| 2023 |
bool IsDoc = false; |
| 2024 |
osl::FileStatus aFileStatus( n_Mask ); |
| 2025 |
aDirItem.getFileStatus( aFileStatus ); |
| 2026 |
if( aFileStatus.isValid( osl_FileStatus_Mask_Type ) ) |
| 2027 |
IsDoc = aFileStatus.getFileType() == osl::FileStatus::Regular; |
| 2028 |
|
| 2029 |
// Getting the information for the next recursive copy |
| 2030 |
FileUrlType newTypeToCopy = IsDoc ? FileUrlType::File : FileUrlType::Folder; |
| 2031 |
|
| 2032 |
OUString newSrcUnqPath; |
| 2033 |
if( aFileStatus.isValid( osl_FileStatus_Mask_FileURL ) ) |
| 2034 |
newSrcUnqPath = aFileStatus.getFileURL(); |
| 2035 |
|
| 2036 |
OUString newDstUnqPath = dstUnqPath; |
| 2037 |
OUString tit; |
| 2038 |
if( aFileStatus.isValid( osl_FileStatus_Mask_FileName ) ) |
| 2039 |
tit = rtl::Uri::encode( aFileStatus.getFileName(), |
| 2040 |
rtl_UriCharClassPchar, |
| 2041 |
rtl_UriEncodeIgnoreEscapes, |
| 2042 |
RTL_TEXTENCODING_UTF8 ); |
| 2043 |
|
| 2044 |
if( !newDstUnqPath.endsWith( "/" ) ) |
| 2045 |
newDstUnqPath += "/"; |
| 2046 |
|
| 2047 |
newDstUnqPath += tit; |
| 2048 |
|
| 2049 |
if ( newSrcUnqPath != dstUnqPath ) |
| 2050 |
err = copy_recursive( newSrcUnqPath,newDstUnqPath,newTypeToCopy,false ); |
| 2051 |
} |
| 2052 |
|
| 2053 |
if( err == osl::FileBase::E_None && next != osl::FileBase::E_NOENT ) |
| 2054 |
err = next; |
| 2055 |
} |
| 2056 |
aDir.close(); |
| 2057 |
} |
| 2058 |
|
| 2059 |
return err; |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
// Helper function for mkfil,mkdir and write |
| 2064 |
// Creates whole path |
| 2065 |
// returns success of the operation |
| 2066 |
|
| 2067 |
|
| 2068 |
bool TaskManager::ensuredir( sal_Int32 CommandId, |
| 2069 |
const OUString& rUnqPath, |
| 2070 |
TaskHandlerErr errorCode ) |
| 2071 |
{ |
| 2072 |
OUString aPath; |
| 2073 |
|
| 2074 |
if ( rUnqPath.isEmpty() ) |
| 2075 |
return false; |
| 2076 |
|
| 2077 |
if ( rUnqPath.endsWith("/") ) |
| 2078 |
aPath = rUnqPath.copy( 0, rUnqPath.getLength() - 1 ); |
| 2079 |
else |
| 2080 |
aPath = rUnqPath; |
| 2081 |
|
| 2082 |
#if HAVE_FEATURE_MACOSX_SANDBOX |
| 2083 |
|
| 2084 |
// Avoid annoying sandbox messages in the system.log from the |
| 2085 |
// below aDirectory.open(), which ends up calling opendir(). |
| 2086 |
// Surely it is easier to just call stat()? Calling stat() on an |
| 2087 |
// arbitrary (?) directory does not seem to cause any sandbox |
| 2088 |
// violation, while opendir() does. (Sorry I could not be bothered |
| 2089 |
// to use some complex cross-platform abstraction over stat() here |
| 2090 |
// in this macOS specific code block.) |
| 2091 |
|
| 2092 |
OUString aDirName; |
| 2093 |
struct stat s; |
| 2094 |
if( osl::FileBase::getSystemPathFromFileURL( aPath, aDirName ) == osl::FileBase::E_None && |
| 2095 |
stat(OUStringToOString( aDirName, RTL_TEXTENCODING_UTF8).getStr(), &s ) == 0 && |
| 2096 |
S_ISDIR( s.st_mode ) ) |
| 2097 |
return sal_True; |
| 2098 |
#endif |
| 2099 |
|
| 2100 |
// HACK: create directory on a mount point with nobrowse option |
| 2101 |
// returns ENOSYS in any case !! |
| 2102 |
osl::Directory aDirectory( aPath ); |
| 2103 |
osl::FileBase::RC nError = aDirectory.open(); |
| 2104 |
aDirectory.close(); |
| 2105 |
|
| 2106 |
if( nError == osl::File::E_None ) |
| 2107 |
return true; |
| 2108 |
|
| 2109 |
nError = osl::Directory::create( aPath ); |
| 2110 |
|
| 2111 |
if( nError == osl::File::E_None ) |
| 2112 |
notifyInsert( getContentEventListeners( getParentName( aPath ) ),aPath ); |
| 2113 |
|
| 2114 |
bool bSuccess = ( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST ); |
| 2115 |
|
| 2116 |
if( ! bSuccess ) |
| 2117 |
{ |
| 2118 |
OUString aParentDir = getParentName( aPath ); |
| 2119 |
|
| 2120 |
if ( aParentDir != aPath ) |
| 2121 |
{ // Create first the parent directory |
| 2122 |
bSuccess = ensuredir( CommandId, |
| 2123 |
getParentName( aPath ), |
| 2124 |
errorCode ); |
| 2125 |
|
| 2126 |
// After parent directory structure exists try it one's more |
| 2127 |
|
| 2128 |
if ( bSuccess ) |
| 2129 |
{ // Parent directory exists, retry creation of directory |
| 2130 |
nError = osl::Directory::create( aPath ); |
| 2131 |
|
| 2132 |
if( nError == osl::File::E_None ) |
| 2133 |
notifyInsert( getContentEventListeners( getParentName( aPath ) ),aPath ); |
| 2134 |
|
| 2135 |
bSuccess =( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST ); |
| 2136 |
} |
| 2137 |
} |
| 2138 |
} |
| 2139 |
|
| 2140 |
if( ! bSuccess ) |
| 2141 |
installError( CommandId, |
| 2142 |
errorCode, |
| 2143 |
nError ); |
| 2144 |
|
| 2145 |
return bSuccess; |
| 2146 |
} |
| 2147 |
|
| 2148 |
|
| 2149 |
// Given a sequence of properties seq, this method determines the mask |
| 2150 |
// used to instantiate an osl::FileStatus, so that a call to |
| 2151 |
// osl::DirectoryItem::getFileStatus fills the required fields. |
| 2152 |
|
| 2153 |
|
| 2154 |
void |
| 2155 |
TaskManager::getMaskFromProperties( |
| 2156 |
sal_Int32& n_Mask, |
| 2157 |
const uno::Sequence< beans::Property >& seq ) |
| 2158 |
{ |
| 2159 |
n_Mask = 0; |
| 2160 |
for(const auto& rProp : seq) { |
| 2161 |
if(rProp.Name == Title) |
| 2162 |
n_Mask |= osl_FileStatus_Mask_FileName; |
| 2163 |
else if(rProp.Name == CasePreservingURL) |
| 2164 |
n_Mask |= osl_FileStatus_Mask_FileURL; |
| 2165 |
else if(rProp.Name == IsDocument || |
| 2166 |
rProp.Name == IsFolder || |
| 2167 |
rProp.Name == IsVolume || |
| 2168 |
rProp.Name == IsRemoveable || |
| 2169 |
rProp.Name == IsRemote || |
| 2170 |
rProp.Name == IsCompactDisc || |
| 2171 |
rProp.Name == IsFloppy || |
| 2172 |
rProp.Name == ContentType) |
| 2173 |
n_Mask |= (osl_FileStatus_Mask_Type | osl_FileStatus_Mask_LinkTargetURL); |
| 2174 |
else if(rProp.Name == Size) |
| 2175 |
n_Mask |= (osl_FileStatus_Mask_FileSize | |
| 2176 |
osl_FileStatus_Mask_Type | |
| 2177 |
osl_FileStatus_Mask_LinkTargetURL); |
| 2178 |
else if(rProp.Name == IsHidden || |
| 2179 |
rProp.Name == IsReadOnly) |
| 2180 |
n_Mask |= osl_FileStatus_Mask_Attributes; |
| 2181 |
else if(rProp.Name == DateModified) |
| 2182 |
n_Mask |= osl_FileStatus_Mask_ModifyTime; |
| 2183 |
} |
| 2184 |
} |
| 2185 |
|
| 2186 |
|
| 2187 |
/*********************************************************************************/ |
| 2188 |
/* */ |
| 2189 |
/* load-Implementation */ |
| 2190 |
/* */ |
| 2191 |
/*********************************************************************************/ |
| 2192 |
|
| 2193 |
// Load the properties from configuration, if create == true create them. |
| 2194 |
// The Properties are stored under the url belonging to it->first. |
| 2195 |
|
| 2196 |
|
| 2197 |
void |
| 2198 |
TaskManager::load( const ContentMap::iterator& it, bool create ) |
| 2199 |
{ |
| 2200 |
if( ( it->second.xS.is() && it->second.xC.is() && it->second.xA.is() ) |
| 2201 |
|| !m_xFileRegistry.is() ) |
| 2202 |
return; |
| 2203 |
|
| 2204 |
|
| 2205 |
uno::Reference< ucb::XPersistentPropertySet > xS = m_xFileRegistry->openPropertySet( it->first,create ); |
| 2206 |
if( xS.is() ) |
| 2207 |
{ |
| 2208 |
it->second.xS = xS; |
| 2209 |
it->second.xC.set(xS, uno::UNO_QUERY); |
| 2210 |
it->second.xA.set(xS, uno::UNO_QUERY); |
| 2211 |
|
| 2212 |
// Now put in all values in the storage in the local hash; |
| 2213 |
|
| 2214 |
PropertySet& properties = it->second.properties; |
| 2215 |
const uno::Sequence< beans::Property > seq = xS->getPropertySetInfo()->getProperties(); |
| 2216 |
|
| 2217 |
for( const auto& rProp : seq ) |
| 2218 |
{ |
| 2219 |
MyProperty readProp( false, |
| 2220 |
rProp.Name, |
| 2221 |
rProp.Handle, |
| 2222 |
rProp.Type, |
| 2223 |
xS->getPropertyValue( rProp.Name ), |
| 2224 |
beans::PropertyState_DIRECT_VALUE, |
| 2225 |
rProp.Attributes ); |
| 2226 |
properties.insert( readProp ); |
| 2227 |
} |
| 2228 |
} |
| 2229 |
else if( create ) |
| 2230 |
{ |
| 2231 |
// Catastrophic error |
| 2232 |
} |
| 2233 |
} |
| 2234 |
|
| 2235 |
|
| 2236 |
/*********************************************************************************/ |
| 2237 |
/* */ |
| 2238 |
/* commit-Implementation */ |
| 2239 |
/* */ |
| 2240 |
/*********************************************************************************/ |
| 2241 |
// Commit inserts the determined properties in the filestatus object into |
| 2242 |
// the internal map, so that is possible to determine on a subsequent |
| 2243 |
// setting of file properties which properties have changed without filestat |
| 2244 |
|
| 2245 |
|
| 2246 |
void |
| 2247 |
TaskManager::commit( std::unique_lock<std::mutex>& rGuard, |
| 2248 |
const TaskManager::ContentMap::iterator& it, |
| 2249 |
const osl::FileStatus& aFileStatus ) |
| 2250 |
{ |
| 2251 |
TaskManager::PropertySet::const_iterator it1; |
| 2252 |
|
| 2253 |
if( it->second.properties.empty() ) |
| 2254 |
{ |
| 2255 |
OUString aPath = it->first; |
| 2256 |
insertDefaultProperties( rGuard, aPath ); |
| 2257 |
} |
| 2258 |
|
| 2259 |
PropertySet& properties = it->second.properties; |
| 2260 |
|
| 2261 |
it1 = properties.find( MyProperty( Title ) ); |
| 2262 |
if( it1 != properties.end() ) |
| 2263 |
{ |
| 2264 |
if( aFileStatus.isValid( osl_FileStatus_Mask_FileName ) ) |
| 2265 |
{ |
| 2266 |
it1->setValue( uno::Any(aFileStatus.getFileName()) ); |
| 2267 |
} |
| 2268 |
} |
| 2269 |
|
| 2270 |
it1 = properties.find( MyProperty( CasePreservingURL ) ); |
| 2271 |
if( it1 != properties.end() ) |
| 2272 |
{ |
| 2273 |
if( aFileStatus.isValid( osl_FileStatus_Mask_FileURL ) ) |
| 2274 |
{ |
| 2275 |
it1->setValue( uno::Any(aFileStatus.getFileURL()) ); |
| 2276 |
} |
| 2277 |
} |
| 2278 |
|
| 2279 |
|
| 2280 |
bool isDirectory; |
| 2281 |
|
| 2282 |
sal_Int64 dirSize = 0; |
| 2283 |
|
| 2284 |
if( aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) ) |
| 2285 |
dirSize = aFileStatus.getFileSize(); |
| 2286 |
|
| 2287 |
if( aFileStatus.isValid( osl_FileStatus_Mask_Type ) ) |
| 2288 |
{ |
| 2289 |
bool isFile,isVolume; |
| 2290 |
if( osl::FileStatus::Link == aFileStatus.getFileType() && |
| 2291 |
aFileStatus.isValid( osl_FileStatus_Mask_LinkTargetURL ) ) |
| 2292 |
{ |
| 2293 |
osl::DirectoryItem aDirItem; |
| 2294 |
osl::FileStatus aFileStatus2( osl_FileStatus_Mask_Type ); |
| 2295 |
if( osl::FileBase::E_None == osl::DirectoryItem::get( aFileStatus.getLinkTargetURL(),aDirItem ) && |
| 2296 |
osl::FileBase::E_None == aDirItem.getFileStatus( aFileStatus2 ) && |
| 2297 |
aFileStatus2.isValid( osl_FileStatus_Mask_Type ) ) |
| 2298 |
{ |
| 2299 |
isVolume = osl::FileStatus::Volume == aFileStatus2.getFileType(); |
| 2300 |
isDirectory = |
| 2301 |
osl::FileStatus::Volume == aFileStatus2.getFileType() || |
| 2302 |
osl::FileStatus::Directory == aFileStatus2.getFileType(); |
| 2303 |
isFile = |
| 2304 |
osl::FileStatus::Regular == aFileStatus2.getFileType(); |
| 2305 |
|
| 2306 |
if( aFileStatus2.isValid( osl_FileStatus_Mask_FileSize ) ) |
| 2307 |
dirSize = aFileStatus2.getFileSize(); |
| 2308 |
} |
| 2309 |
else |
| 2310 |
{ |
| 2311 |
// extremely ugly, but otherwise default construction |
| 2312 |
// of aDirItem and aFileStatus2 |
| 2313 |
// before the preceding if |
| 2314 |
isVolume = osl::FileStatus::Volume == aFileStatus.getFileType(); |
| 2315 |
isDirectory = |
| 2316 |
osl::FileStatus::Volume == aFileStatus.getFileType() || |
| 2317 |
osl::FileStatus::Directory == aFileStatus.getFileType(); |
| 2318 |
isFile = |
| 2319 |
osl::FileStatus::Regular == aFileStatus.getFileType(); |
| 2320 |
} |
| 2321 |
} |
| 2322 |
else |
| 2323 |
{ |
| 2324 |
isVolume = osl::FileStatus::Volume == aFileStatus.getFileType(); |
| 2325 |
isDirectory = |
| 2326 |
osl::FileStatus::Volume == aFileStatus.getFileType() || |
| 2327 |
osl::FileStatus::Directory == aFileStatus.getFileType(); |
| 2328 |
isFile = |
| 2329 |
osl::FileStatus::Regular == aFileStatus.getFileType(); |
| 2330 |
} |
| 2331 |
|
| 2332 |
it1 = properties.find( MyProperty( IsVolume ) ); |
| 2333 |
if( it1 != properties.end() ) |
| 2334 |
it1->setValue( uno::Any( isVolume ) ); |
| 2335 |
|
| 2336 |
it1 = properties.find( MyProperty( IsFolder ) ); |
| 2337 |
if( it1 != properties.end() ) |
| 2338 |
it1->setValue( uno::Any( isDirectory ) ); |
| 2339 |
|
| 2340 |
it1 = properties.find( MyProperty( IsDocument ) ); |
| 2341 |
if( it1 != properties.end() ) |
| 2342 |
it1->setValue( uno::Any( isFile ) ); |
| 2343 |
|
| 2344 |
osl::VolumeInfo aVolumeInfo( osl_VolumeInfo_Mask_Attributes ); |
| 2345 |
if( isVolume && |
| 2346 |
osl::FileBase::E_None == osl::Directory::getVolumeInfo( it->first,aVolumeInfo ) && |
| 2347 |
aVolumeInfo.isValid( osl_VolumeInfo_Mask_Attributes ) ) |
| 2348 |
{ |
| 2349 |
// Retrieve the flags; |
| 2350 |
bool isRemote = aVolumeInfo.getRemoteFlag(); |
| 2351 |
bool isRemoveable = aVolumeInfo.getRemoveableFlag(); |
| 2352 |
bool isCompactDisc = aVolumeInfo.getCompactDiscFlag(); |
| 2353 |
bool isFloppy = aVolumeInfo.getFloppyDiskFlag(); |
| 2354 |
|
| 2355 |
it1 = properties.find( MyProperty( IsRemote ) ); |
| 2356 |
if( it1 != properties.end() ) |
| 2357 |
it1->setValue( uno::Any( isRemote ) ); |
| 2358 |
|
| 2359 |
it1 = properties.find( MyProperty( IsRemoveable ) ); |
| 2360 |
if( it1 != properties.end() ) |
| 2361 |
it1->setValue( uno::Any( isRemoveable ) ); |
| 2362 |
|
| 2363 |
it1 = properties.find( MyProperty( IsCompactDisc ) ); |
| 2364 |
if( it1 != properties.end() ) |
| 2365 |
it1->setValue( uno::Any( isCompactDisc ) ); |
| 2366 |
|
| 2367 |
it1 = properties.find( MyProperty( IsFloppy ) ); |
| 2368 |
if( it1 != properties.end() ) |
| 2369 |
it1->setValue( uno::Any( isFloppy ) ); |
| 2370 |
} |
| 2371 |
else |
| 2372 |
{ |
| 2373 |
uno::Any aAny(false); |
| 2374 |
it1 = properties.find( MyProperty( IsRemote ) ); |
| 2375 |
if( it1 != properties.end() ) |
| 2376 |
it1->setValue( aAny ); |
| 2377 |
|
| 2378 |
it1 = properties.find( MyProperty( IsRemoveable ) ); |
| 2379 |
if( it1 != properties.end() ) |
| 2380 |
it1->setValue( aAny ); |
| 2381 |
|
| 2382 |
it1 = properties.find( MyProperty( IsCompactDisc ) ); |
| 2383 |
if( it1 != properties.end() ) |
| 2384 |
it1->setValue( aAny ); |
| 2385 |
|
| 2386 |
it1 = properties.find( MyProperty( IsFloppy ) ); |
| 2387 |
if( it1 != properties.end() ) |
| 2388 |
it1->setValue( aAny ); |
| 2389 |
} |
| 2390 |
} |
| 2391 |
else |
| 2392 |
{ |
| 2393 |
isDirectory = false; |
| 2394 |
} |
| 2395 |
|
| 2396 |
it1 = properties.find( MyProperty( Size ) ); |
| 2397 |
if( it1 != properties.end() ) |
| 2398 |
it1->setValue( uno::Any( dirSize ) ); |
| 2399 |
|
| 2400 |
it1 = properties.find( MyProperty( IsReadOnly ) ); |
| 2401 |
if( it1 != properties.end() ) |
| 2402 |
{ |
| 2403 |
if( aFileStatus.isValid( osl_FileStatus_Mask_Attributes ) ) |
| 2404 |
{ |
| 2405 |
sal_uInt64 Attr = aFileStatus.getAttributes(); |
| 2406 |
bool readonly = ( Attr & osl_File_Attribute_ReadOnly ) != 0; |
| 2407 |
it1->setValue( uno::Any( readonly ) ); |
| 2408 |
} |
| 2409 |
} |
| 2410 |
|
| 2411 |
it1 = properties.find( MyProperty( IsHidden ) ); |
| 2412 |
if( it1 != properties.end() ) |
| 2413 |
{ |
| 2414 |
if( aFileStatus.isValid( osl_FileStatus_Mask_Attributes ) ) |
| 2415 |
{ |
| 2416 |
sal_uInt64 Attr = aFileStatus.getAttributes(); |
| 2417 |
bool ishidden = ( Attr & osl_File_Attribute_Hidden ) != 0; |
| 2418 |
it1->setValue( uno::Any( ishidden ) ); |
| 2419 |
} |
| 2420 |
} |
| 2421 |
|
| 2422 |
it1 = properties.find( MyProperty( DateModified ) ); |
| 2423 |
if( it1 != properties.end() ) |
| 2424 |
{ |
| 2425 |
if( aFileStatus.isValid( osl_FileStatus_Mask_ModifyTime ) ) |
| 2426 |
{ |
| 2427 |
TimeValue temp = aFileStatus.getModifyTime(); |
| 2428 |
|
| 2429 |
// Convert system time to local time (for EA) |
| 2430 |
TimeValue myLocalTime; |
| 2431 |
if (!osl_getLocalTimeFromSystemTime( &temp, &myLocalTime )) |
| 2432 |
{ |
| 2433 |
SAL_WARN( |
| 2434 |
"ucb.ucp.file", |
| 2435 |
"cannot convert (" << temp.Seconds << ", " << temp.Nanosec |
| 2436 |
<< ") to local time"); |
| 2437 |
myLocalTime = temp; |
| 2438 |
} |
| 2439 |
|
| 2440 |
oslDateTime myDateTime; |
| 2441 |
osl_getDateTimeFromTimeValue( &myLocalTime, &myDateTime ); |
| 2442 |
util::DateTime aDateTime; |
| 2443 |
|
| 2444 |
aDateTime.NanoSeconds = myDateTime.NanoSeconds; |
| 2445 |
aDateTime.Seconds = myDateTime.Seconds; |
| 2446 |
aDateTime.Minutes = myDateTime.Minutes; |
| 2447 |
aDateTime.Hours = myDateTime.Hours; |
| 2448 |
aDateTime.Day = myDateTime.Day; |
| 2449 |
aDateTime.Month = myDateTime.Month; |
| 2450 |
aDateTime.Year = myDateTime.Year; |
| 2451 |
it1->setValue( uno::Any( aDateTime ) ); |
| 2452 |
} |
| 2453 |
} |
| 2454 |
|
| 2455 |
it1 = properties.find( MyProperty( CreatableContentsInfo ) ); |
| 2456 |
if( it1 != properties.end() ) |
| 2457 |
it1->setValue( uno::Any( |
| 2458 |
isDirectory || !aFileStatus.isValid( osl_FileStatus_Mask_Type ) |
| 2459 |
? queryCreatableContentsInfo() |
| 2460 |
: uno::Sequence< ucb::ContentInfo >() ) ); |
| 2461 |
} |
| 2462 |
|
| 2463 |
|
| 2464 |
// Special optimized method for getting the properties of a |
| 2465 |
// directoryitem, which is returned by osl::DirectoryItem::getNextItem() |
| 2466 |
|
| 2467 |
|
| 2468 |
bool |
| 2469 |
TaskManager::getv( |
| 2470 |
const uno::Sequence< beans::Property >& properties, |
| 2471 |
osl::DirectoryItem& aDirItem, |
| 2472 |
OUString& aUnqPath, |
| 2473 |
bool& aIsRegular, |
| 2474 |
uno::Reference< sdbc::XRow > & row ) |
| 2475 |
{ |
| 2476 |
uno::Sequence< uno::Any > seq( properties.getLength() ); |
| 2477 |
|
| 2478 |
sal_Int32 n_Mask; |
| 2479 |
getMaskFromProperties( n_Mask,properties ); |
| 2480 |
|
| 2481 |
// Always retrieve the type and the target URL because item might be a link |
| 2482 |
osl::FileStatus aFileStatus( n_Mask | |
| 2483 |
osl_FileStatus_Mask_FileURL | |
| 2484 |
osl_FileStatus_Mask_Type | |
| 2485 |
osl_FileStatus_Mask_LinkTargetURL ); |
| 2486 |
|
| 2487 |
osl::FileBase::RC aRes = aDirItem.getFileStatus( aFileStatus ); |
| 2488 |
if ( aRes != osl::FileBase::E_None ) |
| 2489 |
{ |
| 2490 |
SAL_WARN( |
| 2491 |
"ucb.ucp.file", |
| 2492 |
"osl::DirectoryItem::getFileStatus failed with " << +aRes); |
| 2493 |
return false; |
| 2494 |
} |
| 2495 |
|
| 2496 |
aUnqPath = aFileStatus.getFileURL(); |
| 2497 |
|
| 2498 |
// If the directory item type is a link retrieve the type of the target |
| 2499 |
|
| 2500 |
if ( aFileStatus.getFileType() == osl::FileStatus::Link ) |
| 2501 |
{ |
| 2502 |
// Assume failure |
| 2503 |
aIsRegular = false; |
| 2504 |
osl::DirectoryItem aTargetItem; |
| 2505 |
(void)osl::DirectoryItem::get( aFileStatus.getLinkTargetURL(), aTargetItem ); |
| 2506 |
if ( aTargetItem.is() ) |
| 2507 |
{ |
| 2508 |
osl::FileStatus aTargetStatus( osl_FileStatus_Mask_Type ); |
| 2509 |
|
| 2510 |
if ( osl::FileBase::E_None == aTargetItem.getFileStatus( aTargetStatus ) ) |
| 2511 |
aIsRegular = |
| 2512 |
aTargetStatus.getFileType() == osl::FileStatus::Regular; |
| 2513 |
} |
| 2514 |
} |
| 2515 |
else |
| 2516 |
aIsRegular = aFileStatus.getFileType() == osl::FileStatus::Regular; |
| 2517 |
|
| 2518 |
{ |
| 2519 |
std::unique_lock aGuard( m_aMutex ); |
| 2520 |
|
| 2521 |
insertDefaultProperties( aGuard, aUnqPath ); |
| 2522 |
|
| 2523 |
TaskManager::ContentMap::iterator it = m_aContent.find( aUnqPath ); |
| 2524 |
commit( aGuard, it, aFileStatus ); |
| 2525 |
|
| 2526 |
PropertySet& propset = it->second.properties; |
| 2527 |
|
| 2528 |
std::transform(properties.begin(), properties.end(), seq.getArray(), |
| 2529 |
[&propset](const beans::Property& rProp) -> uno::Any { |
| 2530 |
MyProperty readProp( rProp.Name ); |
| 2531 |
auto it1 = propset.find( readProp ); |
| 2532 |
if( it1 == propset.end() ) |
| 2533 |
return uno::Any(); |
| 2534 |
return it1->getValue(); |
| 2535 |
}); |
| 2536 |
} |
| 2537 |
|
| 2538 |
row = new XRow_impl( this,seq ); |
| 2539 |
return true; |
| 2540 |
} |
| 2541 |
|
| 2542 |
|
| 2543 |
// EventListener |
| 2544 |
|
| 2545 |
|
| 2546 |
std::vector< ContentEventNotifier > |
| 2547 |
TaskManager::getContentEventListeners( const OUString& aName ) |
| 2548 |
{ |
| 2549 |
std::vector< ContentEventNotifier > listeners; |
| 2550 |
{ |
| 2551 |
std::unique_lock aGuard( m_aMutex ); |
| 2552 |
TaskManager::ContentMap::iterator it = m_aContent.find( aName ); |
| 2553 |
if( it != m_aContent.end() && !it->second.notifier.empty() ) |
| 2554 |
{ |
| 2555 |
std::vector<Notifier*>& listOfNotifiers = it->second.notifier; |
| 2556 |
for (auto const& pointer : listOfNotifiers) |
| 2557 |
{ |
| 2558 |
std::optional<ContentEventNotifier> notifier = pointer->cCEL(); |
| 2559 |
if( notifier ) |
| 2560 |
listeners.push_back( std::move(*notifier) ); |
| 2561 |
} |
| 2562 |
} |
| 2563 |
} |
| 2564 |
return listeners; |
| 2565 |
} |
| 2566 |
|
| 2567 |
|
| 2568 |
std::vector< ContentEventNotifier > |
| 2569 |
TaskManager::getContentDeletedEventListeners( const OUString& aName ) |
| 2570 |
{ |
| 2571 |
std::vector< ContentEventNotifier > listeners; |
| 2572 |
{ |
| 2573 |
std::unique_lock aGuard( m_aMutex ); |
| 2574 |
TaskManager::ContentMap::iterator it = m_aContent.find( aName ); |
| 2575 |
if( it != m_aContent.end() && !it->second.notifier.empty() ) |
| 2576 |
{ |
| 2577 |
std::vector<Notifier*>& listOfNotifiers = it->second.notifier; |
| 2578 |
for (auto const& pointer : listOfNotifiers) |
| 2579 |
{ |
| 2580 |
std::optional<ContentEventNotifier> notifier = pointer->cDEL(); |
| 2581 |
if( notifier ) |
| 2582 |
listeners.push_back( std::move(*notifier) ); |
| 2583 |
} |
| 2584 |
} |
| 2585 |
} |
| 2586 |
return listeners; |
| 2587 |
} |
| 2588 |
|
| 2589 |
void TaskManager::notifyInsert(const std::vector<ContentEventNotifier>& listeners, |
| 2590 |
const OUString& aChildName) |
| 2591 |
{ |
| 2592 |
for (const auto & l : listeners ) |
| 2593 |
{ |
| 2594 |
l.notifyChildInserted( aChildName ); |
| 2595 |
} |
| 2596 |
} |
| 2597 |
|
| 2598 |
void TaskManager::notifyContentDeleted( |
| 2599 |
const std::vector<ContentEventNotifier>& listeners) |
| 2600 |
{ |
| 2601 |
for( auto const & l : listeners ) |
| 2602 |
{ |
| 2603 |
l.notifyDeleted(); |
| 2604 |
} |
| 2605 |
} |
| 2606 |
|
| 2607 |
void TaskManager::notifyContentRemoved( |
| 2608 |
const std::vector<ContentEventNotifier>& listeners, const OUString& aChildName) |
| 2609 |
{ |
| 2610 |
for( auto const & l : listeners ) |
| 2611 |
{ |
| 2612 |
l.notifyRemoved( aChildName ); |
| 2613 |
} |
| 2614 |
} |
| 2615 |
|
| 2616 |
|
| 2617 |
std::vector< PropertySetInfoChangeNotifier > |
| 2618 |
TaskManager::getPropertySetListeners( const OUString& aName ) |
| 2619 |
{ |
| 2620 |
std::vector< PropertySetInfoChangeNotifier > listeners; |
| 2621 |
{ |
| 2622 |
std::unique_lock aGuard( m_aMutex ); |
| 2623 |
TaskManager::ContentMap::iterator it = m_aContent.find( aName ); |
| 2624 |
if( it != m_aContent.end() && !it->second.notifier.empty() ) |
| 2625 |
{ |
| 2626 |
std::vector<Notifier*>& listOfNotifiers = it->second.notifier; |
| 2627 |
for (auto const& pointer : listOfNotifiers) |
| 2628 |
{ |
| 2629 |
std::optional<PropertySetInfoChangeNotifier> notifier = pointer->cPSL(); |
| 2630 |
if( notifier ) |
| 2631 |
listeners.push_back( std::move(*notifier) ); |
| 2632 |
} |
| 2633 |
} |
| 2634 |
} |
| 2635 |
return listeners; |
| 2636 |
} |
| 2637 |
|
| 2638 |
void TaskManager::notifyPropertyAdded( |
| 2639 |
const std::vector<PropertySetInfoChangeNotifier>& listeners, |
| 2640 |
const OUString& aPropertyName) |
| 2641 |
{ |
| 2642 |
for( auto const & l : listeners ) |
| 2643 |
{ |
| 2644 |
l.notifyPropertyAdded( aPropertyName ); |
| 2645 |
} |
| 2646 |
} |
| 2647 |
|
| 2648 |
void TaskManager::notifyPropertyRemoved( |
| 2649 |
const std::vector<PropertySetInfoChangeNotifier>& listeners, |
| 2650 |
const OUString& aPropertyName) |
| 2651 |
{ |
| 2652 |
for( auto const & l : listeners ) |
| 2653 |
{ |
| 2654 |
l.notifyPropertyRemoved( aPropertyName ); |
| 2655 |
} |
| 2656 |
} |
| 2657 |
|
| 2658 |
|
| 2659 |
std::vector< ContentEventNotifier > |
| 2660 |
TaskManager::getContentExchangedEventListeners( const OUString& aOldPrefix, |
| 2661 |
const OUString& aNewPrefix, |
| 2662 |
bool withChildren ) |
| 2663 |
{ |
| 2664 |
std::vector< ContentEventNotifier > aVector; |
| 2665 |
|
| 2666 |
sal_Int32 count; |
| 2667 |
OUString aOldName; |
| 2668 |
OUString aNewName; |
| 2669 |
std::vector< OUString > oldChildList; |
| 2670 |
|
| 2671 |
{ |
| 2672 |
std::unique_lock aGuard( m_aMutex ); |
| 2673 |
|
| 2674 |
if( ! withChildren ) |
| 2675 |
{ |
| 2676 |
aOldName = aOldPrefix; |
| 2677 |
aNewName = aNewPrefix; |
| 2678 |
count = 1; |
| 2679 |
} |
| 2680 |
else |
| 2681 |
{ |
| 2682 |
for (auto const& content : m_aContent) |
| 2683 |
{ |
| 2684 |
if( isChild( aOldPrefix, content.first ) ) |
| 2685 |
{ |
| 2686 |
oldChildList.push_back( content.first ); |
| 2687 |
} |
| 2688 |
} |
| 2689 |
count = oldChildList.size(); |
| 2690 |
} |
| 2691 |
|
| 2692 |
|
| 2693 |
for( sal_Int32 j = 0; j < count; ++j ) |
| 2694 |
{ |
| 2695 |
if( withChildren ) |
| 2696 |
{ |
| 2697 |
aOldName = oldChildList[j]; |
| 2698 |
aNewName = newName( aNewPrefix,aOldPrefix,aOldName ); |
| 2699 |
} |
| 2700 |
|
| 2701 |
TaskManager::ContentMap::iterator itold = m_aContent.find( aOldName ); |
| 2702 |
if( itold != m_aContent.end() ) |
| 2703 |
{ |
| 2704 |
TaskManager::ContentMap::iterator itnew = m_aContent.emplace( |
| 2705 |
aNewName,UnqPathData() ).first; |
| 2706 |
|
| 2707 |
// copy Ownership also |
| 2708 |
itnew->second.properties = std::move(itold->second.properties); |
| 2709 |
|
| 2710 |
// copy existing list |
| 2711 |
std::vector< Notifier* > copyList; |
| 2712 |
std::swap(copyList, itnew->second.notifier); |
| 2713 |
itnew->second.notifier = std::move(itold->second.notifier); |
| 2714 |
|
| 2715 |
m_aContent.erase( itold ); |
| 2716 |
|
| 2717 |
if (itnew != m_aContent.end()) |
| 2718 |
{ |
| 2719 |
if (!itnew->second.notifier.empty()) |
| 2720 |
{ |
| 2721 |
std::vector<Notifier*>& listOfNotifiers = itnew->second.notifier; |
| 2722 |
for (auto const& pointer : listOfNotifiers) |
| 2723 |
{ |
| 2724 |
std::optional<ContentEventNotifier> notifier = pointer->cEXC( aNewName ); |
| 2725 |
if( notifier ) |
| 2726 |
aVector.push_back( std::move(*notifier) ); |
| 2727 |
} |
| 2728 |
} |
| 2729 |
|
| 2730 |
// Merge with preexisting notifiers |
| 2731 |
// However, these may be in status BaseContent::Deleted |
| 2732 |
itnew->second.notifier.insert(itnew->second.notifier.end(), |
| 2733 |
copyList.begin(), copyList.end() ); |
| 2734 |
} |
| 2735 |
} |
| 2736 |
} |
| 2737 |
} |
| 2738 |
|
| 2739 |
return aVector; |
| 2740 |
} |
| 2741 |
|
| 2742 |
void TaskManager::notifyContentExchanged( |
| 2743 |
const std::vector<ContentEventNotifier>& listeners_vec) |
| 2744 |
{ |
| 2745 |
for( auto & l : listeners_vec) |
| 2746 |
{ |
| 2747 |
l.notifyExchanged(); |
| 2748 |
} |
| 2749 |
} |
| 2750 |
|
| 2751 |
|
| 2752 |
std::vector< PropertyChangeNotifier > |
| 2753 |
TaskManager::getPropertyChangeNotifier( const OUString& aName ) |
| 2754 |
{ |
| 2755 |
std::vector< PropertyChangeNotifier > listeners; |
| 2756 |
{ |
| 2757 |
std::unique_lock aGuard( m_aMutex ); |
| 2758 |
TaskManager::ContentMap::iterator it = m_aContent.find( aName ); |
| 2759 |
if( it != m_aContent.end() && !it->second.notifier.empty() ) |
| 2760 |
{ |
| 2761 |
std::vector<Notifier*>& listOfNotifiers = it->second.notifier; |
| 2762 |
for (auto const& pointer : listOfNotifiers) |
| 2763 |
{ |
| 2764 |
std::optional<PropertyChangeNotifier> notifier = pointer->cPCL(); |
| 2765 |
if( notifier ) |
| 2766 |
listeners.push_back( std::move(*notifier) ); |
| 2767 |
} |
| 2768 |
} |
| 2769 |
} |
| 2770 |
return listeners; |
| 2771 |
} |
| 2772 |
|
| 2773 |
void TaskManager::notifyPropertyChanges( |
| 2774 |
const std::vector<PropertyChangeNotifier>& listeners, |
| 2775 |
const uno::Sequence<beans::PropertyChangeEvent>& seqChanged) |
| 2776 |
{ |
| 2777 |
for( auto const & l : listeners ) |
| 2778 |
{ |
| 2779 |
l.notifyPropertyChanged( seqChanged ); |
| 2780 |
} |
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
/********************************************************************************/ |
| 2785 |
/* remove persistent propertyset */ |
| 2786 |
/********************************************************************************/ |
| 2787 |
|
| 2788 |
void |
| 2789 |
TaskManager::erasePersistentSetWithoutChildren( const OUString& aUnqPath ) |
| 2790 |
{ |
| 2791 |
{ |
| 2792 |
// Release possible references |
| 2793 |
std::unique_lock aGuard( m_aMutex ); |
| 2794 |
ContentMap::iterator it = m_aContent.find( aUnqPath ); |
| 2795 |
if( it != m_aContent.end() ) |
| 2796 |
{ |
| 2797 |
it->second.xS = nullptr; |
| 2798 |
it->second.xC = nullptr; |
| 2799 |
it->second.xA = nullptr; |
| 2800 |
|
| 2801 |
it->second.properties.clear(); |
| 2802 |
} |
| 2803 |
} |
| 2804 |
|
| 2805 |
m_xFileRegistry->removePropertySet( aUnqPath ); |
| 2806 |
} |
| 2807 |
|
| 2808 |
void |
| 2809 |
TaskManager::erasePersistentSet( const OUString& aUnqPath, |
| 2810 |
bool withChildren ) |
| 2811 |
{ |
| 2812 |
if( ! m_xFileRegistry.is() ) |
| 2813 |
{ |
| 2814 |
OSL_ASSERT( m_xFileRegistry.is() ); |
| 2815 |
return; |
| 2816 |
} |
| 2817 |
|
| 2818 |
if( ! withChildren ) |
| 2819 |
{ |
| 2820 |
erasePersistentSetWithoutChildren(aUnqPath); |
| 2821 |
return; |
| 2822 |
} |
| 2823 |
|
| 2824 |
uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY ); |
| 2825 |
const uno::Sequence< OUString > seqNames = xName->getElementNames(); |
| 2826 |
|
| 2827 |
OUString old_Name = aUnqPath; |
| 2828 |
|
| 2829 |
for( const auto& rName : seqNames ) |
| 2830 |
{ |
| 2831 |
if( ! ( isChild( old_Name,rName ) ) ) |
| 2832 |
continue; |
| 2833 |
|
| 2834 |
old_Name = rName; |
| 2835 |
|
| 2836 |
erasePersistentSetWithoutChildren(old_Name); |
| 2837 |
} |
| 2838 |
} |
| 2839 |
|
| 2840 |
|
| 2841 |
/********************************************************************************/ |
| 2842 |
/* copy persistent propertyset */ |
| 2843 |
/* from srcUnqPath to dstUnqPath */ |
| 2844 |
/********************************************************************************/ |
| 2845 |
|
| 2846 |
void |
| 2847 |
TaskManager::copyPersistentSetWithoutChildren( const OUString& srcUnqPath, |
| 2848 |
const OUString& dstUnqPath ) |
| 2849 |
{ |
| 2850 |
uno::Reference< XPersistentPropertySet > x_src = |
| 2851 |
m_xFileRegistry->openPropertySet( srcUnqPath,false ); |
| 2852 |
m_xFileRegistry->removePropertySet( dstUnqPath ); |
| 2853 |
|
| 2854 |
if( ! x_src.is() ) |
| 2855 |
return; |
| 2856 |
|
| 2857 |
const uno::Sequence< beans::Property > seqProperty = |
| 2858 |
x_src->getPropertySetInfo()->getProperties(); |
| 2859 |
|
| 2860 |
if( ! seqProperty.hasElements() ) |
| 2861 |
return; |
| 2862 |
|
| 2863 |
uno::Reference< XPersistentPropertySet > |
| 2864 |
x_dstS = m_xFileRegistry->openPropertySet( dstUnqPath,true ); |
| 2865 |
uno::Reference< beans::XPropertyContainer > |
| 2866 |
x_dstC( x_dstS,uno::UNO_QUERY ); |
| 2867 |
|
| 2868 |
for( const auto& rProperty : seqProperty ) |
| 2869 |
{ |
| 2870 |
x_dstC->addProperty( rProperty.Name, |
| 2871 |
rProperty.Attributes, |
| 2872 |
x_src->getPropertyValue( rProperty.Name ) ); |
| 2873 |
} |
| 2874 |
} |
| 2875 |
|
| 2876 |
void |
| 2877 |
TaskManager::copyPersistentSet( const OUString& srcUnqPath, |
| 2878 |
const OUString& dstUnqPath, |
| 2879 |
bool withChildren ) |
| 2880 |
{ |
| 2881 |
if( ! m_xFileRegistry.is() ) |
| 2882 |
{ |
| 2883 |
OSL_ASSERT( m_xFileRegistry.is() ); |
| 2884 |
return; |
| 2885 |
} |
| 2886 |
|
| 2887 |
if( ! withChildren ) |
| 2888 |
{ |
| 2889 |
copyPersistentSetWithoutChildren(srcUnqPath, dstUnqPath); |
| 2890 |
return; |
| 2891 |
} |
| 2892 |
|
| 2893 |
uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY ); |
| 2894 |
const uno::Sequence< OUString > seqNames = xName->getElementNames(); |
| 2895 |
|
| 2896 |
OUString new_Name; |
| 2897 |
|
| 2898 |
for( const auto& rName : seqNames ) |
| 2899 |
{ |
| 2900 |
if( ! ( isChild( srcUnqPath,rName ) ) ) |
| 2901 |
continue; |
| 2902 |
|
| 2903 |
new_Name = newName( dstUnqPath,srcUnqPath,rName ); |
| 2904 |
|
| 2905 |
copyPersistentSetWithoutChildren(rName, new_Name); |
| 2906 |
} |
| 2907 |
} |
| 2908 |
|
| 2909 |
uno::Sequence< ucb::ContentInfo > TaskManager::queryCreatableContentsInfo() |
| 2910 |
{ |
| 2911 |
|
| 2912 |
|
| 2913 |
uno::Sequence< beans::Property > props |
| 2914 |
{ |
| 2915 |
{ u"Title"_ustr, -1, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::BOUND } |
| 2916 |
}; |
| 2917 |
return |
| 2918 |
{ |
| 2919 |
{ FileContentType, ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM | ucb::ContentInfoAttribute::KIND_DOCUMENT, props }, |
| 2920 |
{ FolderContentType, ucb::ContentInfoAttribute::KIND_FOLDER, props } |
| 2921 |
}; |
| 2922 |
} |
| 2923 |
|
| 2924 |
/*******************************************************************************/ |
| 2925 |
/* */ |
| 2926 |
/* some miscellaneous static functions */ |
| 2927 |
/* */ |
| 2928 |
/*******************************************************************************/ |
| 2929 |
|
| 2930 |
void |
| 2931 |
TaskManager::getScheme( OUString& Scheme ) |
| 2932 |
{ |
| 2933 |
Scheme = "file"; |
| 2934 |
} |
| 2935 |
|
| 2936 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |