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