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