LibreOffice Module unotools (master) 1
tempfile.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 <sal/config.h>
21
22#include <cassert>
23#include <utility>
24
25#include <com/sun/star/io/BufferSizeExceededException.hpp>
26#include <com/sun/star/io/NotConnectedException.hpp>
27#include <com/sun/star/lang/IllegalArgumentException.hpp>
28#include <unotools/tempfile.hxx>
29#include <rtl/ustring.hxx>
30#include <o3tl/safeint.hxx>
31#include <osl/mutex.hxx>
32#include <osl/detail/file.h>
33#include <osl/file.hxx>
34#include <tools/time.hxx>
35#include <tools/debug.hxx>
36#include <tools/Guid.hxx>
38
39#ifdef UNX
40#include <unistd.h>
41#elif defined( _WIN32 )
42#include <process.h>
43#endif
44
45using namespace osl;
46
47namespace
48{
49 OUString gTempNameBase_Impl;
50}
51
52namespace utl
53{
54
55static OUString getParentName( std::u16string_view aFileName )
56{
57 size_t lastIndex = aFileName.rfind( '/' );
58 OUString aParent;
59
60 if (lastIndex != std::u16string_view::npos)
61 {
62 aParent = aFileName.substr(0, lastIndex);
63
64 if (aParent.endsWith(":") && aParent.getLength() == 6)
65 aParent += "/";
66
67 if (aParent.equalsIgnoreAsciiCase("file://"))
68 aParent = "file:///";
69 }
70
71 return aParent;
72}
73
74static bool ensuredir( const OUString& rUnqPath )
75{
76 OUString aPath;
77 if ( rUnqPath.isEmpty() )
78 return false;
79
80 // remove trailing slash
81 if ( rUnqPath.endsWith("/") )
82 aPath = rUnqPath.copy( 0, rUnqPath.getLength() - 1 );
83 else
84 aPath = rUnqPath;
85
86 // HACK: create directory on a mount point with nobrowse option
87 // returns ENOSYS in any case !!
88 osl::Directory aDirectory( aPath );
89 osl::FileBase::RC nError = aDirectory.open();
90 aDirectory.close();
91 if( nError == osl::File::E_None )
92 return true;
93
94 // try to create the directory
95 nError = osl::Directory::create( aPath );
96 bool bSuccess = ( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST );
97 if( !bSuccess )
98 {
99 // perhaps parent(s) don't exist
100 OUString aParentDir = getParentName( aPath );
101 if ( aParentDir != aPath )
102 {
103 bSuccess = ensuredir( getParentName( aPath ) );
104
105 // After parent directory structure exists try it one's more
106 if ( bSuccess )
107 {
108 // Parent directory exists, retry creation of directory
109 nError = osl::Directory::create( aPath );
110 bSuccess =( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST );
111 }
112 }
113 }
114
115 return bSuccess;
116}
117
118static OUString ConstructTempDir_Impl( const OUString* pParent, bool bCreateParentDirs )
119{
120 OUString aName;
121
122 // Ignore pParent on iOS. We don't want to create any temp files
123 // in the same directory where the document being edited is.
124#ifndef IOS
125 if ( pParent && !pParent->isEmpty() )
126 {
127 // test for valid filename
128 OUString aRet;
129 if ((osl::FileBase::getSystemPathFromFileURL(*pParent, aRet)
130 == osl::FileBase::E_None)
131 && (osl::FileBase::getFileURLFromSystemPath(aRet, aRet)
132 == osl::FileBase::E_None))
133 {
134 ::osl::DirectoryItem aItem;
135 sal_Int32 i = aRet.getLength();
136 if ( aRet[i-1] == '/' )
137 i--;
138
139 if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None || bCreateParentDirs )
140 aName = aRet;
141 }
142 }
143#else
144 (void) pParent;
145 (void) bCreateParentDirs;
146#endif
147
148 if ( aName.isEmpty() )
149 {
150 if (gTempNameBase_Impl.isEmpty())
151 {
152 OUString ustrTempDirURL;
153 ::osl::FileBase::RC rc = ::osl::File::getTempDirURL(
154 ustrTempDirURL );
155 if (rc == ::osl::FileBase::E_None)
156 gTempNameBase_Impl = ustrTempDirURL;
157 ensuredir( aName );
158 }
159 // if no parent or invalid parent : use default directory
160 DBG_ASSERT( !gTempNameBase_Impl.isEmpty(), "No TempDir!" );
161 aName = gTempNameBase_Impl;
162 }
163
164 // Make sure that directory ends with a separator
165 if( !aName.isEmpty() && !aName.endsWith("/") )
166 aName += "/";
167
168 return aName;
169}
170
171namespace {
172
173class Tokens {
174public:
175 virtual bool next(OUString *) = 0;
176
177protected:
178 virtual ~Tokens() {} // avoid warnings
179};
180
181class SequentialTokens: public Tokens {
182public:
183 explicit SequentialTokens(bool showZero): m_value(0), m_show(showZero) {}
184
185 bool next(OUString * token) override {
186 assert(token != nullptr);
187 if (m_value == SAL_MAX_UINT32) {
188 return false;
189 }
190 *token = m_show ? OUString::number(m_value) : OUString();
191 ++m_value;
192 m_show = true;
193 return true;
194 }
195
196private:
197 sal_uInt32 m_value;
198 bool m_show;
199};
200
201class UniqueTokens: public Tokens {
202public:
203 UniqueTokens(): m_count(0) {}
204
205 bool next(OUString * token) override {
206 assert(token != nullptr);
207 // Because of the shared globalValue, no single instance of UniqueTokens
208 // is guaranteed to exhaustively test all 36^6 possible values, but stop
209 // after that many attempts anyway:
210 sal_uInt32 radix = 36;
211 sal_uInt32 max = radix * radix * radix * radix * radix * radix;
212 // 36^6 == 2'176'782'336 < SAL_MAX_UINT32 == 4'294'967'295
213 if (m_count == max) {
214 return false;
215 }
216 sal_uInt32 v;
217 {
218 osl::MutexGuard g(osl::Mutex::getGlobalMutex());
222 % max);
223 v = globalValue;
224 }
225 *token = OUString::number(v, radix);
226 ++m_count;
227 return true;
228 }
229
230private:
231 static sal_uInt32 globalValue;
232
233 sal_uInt32 m_count;
234};
235
236}
237
239
240namespace
241{
242 class TempDirCreatedObserver : public DirectoryCreationObserver
243 {
244 public:
245 virtual void DirectoryCreated(const OUString& aDirectoryUrl) override
246 {
247 File::setAttributes( aDirectoryUrl, osl_File_Attribute_OwnRead |
248 osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnExe );
249 };
250 };
251};
252
253static OUString lcl_createName(
254 std::u16string_view rLeadingChars, Tokens & tokens, std::u16string_view pExtension,
255 const OUString* pParent, bool bDirectory, bool bKeep, bool bLock,
256 bool bCreateParentDirs )
257{
258 OUString aName = ConstructTempDir_Impl( pParent, bCreateParentDirs );
259 if ( bCreateParentDirs )
260 {
261 size_t nOffset = rLeadingChars.rfind(u"/");
262 OUString aDirName;
263 if (std::u16string_view::npos != nOffset)
264 aDirName = aName + rLeadingChars.substr( 0, nOffset );
265 else
266 aDirName = aName;
267 TempDirCreatedObserver observer;
268 FileBase::RC err = Directory::createPath( aDirName, &observer );
269 if ( err != FileBase::E_None && err != FileBase::E_EXIST )
270 return OUString();
271 }
272 aName += rLeadingChars;
273
274 OUString token;
275 while (tokens.next(&token))
276 {
277 OUString aTmp( aName + token );
278 if ( !pExtension.empty() )
279 aTmp += pExtension;
280 else
281 aTmp += ".tmp";
282 if ( bDirectory )
283 {
284 FileBase::RC err = Directory::create(
285 aTmp,
286 (osl_File_OpenFlag_Read | osl_File_OpenFlag_Write
287 | osl_File_OpenFlag_Private));
288 if ( err == FileBase::E_None )
289 {
290 // !bKeep: only for creating a name, not a file or directory
291 if ( bKeep || Directory::remove( aTmp ) == FileBase::E_None )
292 return aTmp;
293 else
294 return OUString();
295 }
296 else if ( err != FileBase::E_EXIST )
297 // if f.e. name contains invalid chars stop trying to create dirs
298 return OUString();
299 }
300 else
301 {
302 DBG_ASSERT( bKeep, "Too expensive, use directory for creating name!" );
303 File aFile( aTmp );
304 FileBase::RC err = aFile.open(
305 osl_File_OpenFlag_Create | osl_File_OpenFlag_Private
306 | (bLock ? 0 : osl_File_OpenFlag_NoLock));
307 if ( err == FileBase::E_None || (bLock && err == FileBase::E_NOLCK) )
308 {
309 aFile.close();
310 return aTmp;
311 }
312 else if ( err != FileBase::E_EXIST )
313 {
314 // if f.e. name contains invalid chars stop trying to create dirs
315 // but if there is a folder with such name proceed further
316
317 DirectoryItem aTmpItem;
318 FileStatus aTmpStatus( osl_FileStatus_Mask_Type );
319 if ( DirectoryItem::get( aTmp, aTmpItem ) != FileBase::E_None
320 || aTmpItem.getFileStatus( aTmpStatus ) != FileBase::E_None
321 || aTmpStatus.getFileType() != FileStatus::Directory )
322 return OUString();
323 }
324 }
325 }
326 return OUString();
327}
328
329static OUString CreateTempName_Impl( const OUString* pParent, bool bKeep, bool bDir = true )
330{
331 OUString aEyeCatcher = "lu";
332#ifdef UNX
333#ifdef DBG_UTIL
334 const char* eye = getenv("LO_TESTNAME");
335 if(eye)
336 {
337 aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
338 }
339#else
340 static const pid_t pid = getpid();
341 static const OUString aPidString = OUString::number(pid);
342 aEyeCatcher += aPidString;
343#endif
344#elif defined(_WIN32)
345 static const int pid = _getpid();
346 static const OUString aPidString = OUString::number(pid);
347 aEyeCatcher += aPidString;
348#endif
349 UniqueTokens t;
350 return lcl_createName( aEyeCatcher, t, u"", pParent, bDir, bKeep,
351 false, false);
352}
353
354static OUString CreateTempNameFast()
355{
356 OUString aEyeCatcher = "lu";
357#ifdef UNX
358#ifdef DBG_UTIL
359 const char* eye = getenv("LO_TESTNAME");
360 if(eye)
361 {
362 aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
363 }
364#else
365 static const pid_t pid = getpid();
366 static const OUString aPidString = OUString::number(pid);
367 aEyeCatcher += aPidString;
368#endif
369#elif defined(_WIN32)
370 static const int pid = _getpid();
371 static const OUString aPidString = OUString::number(pid);
372 aEyeCatcher += aPidString;
373#endif
374
375 OUString aName = ConstructTempDir_Impl( /*pParent*/nullptr, /*bCreateParentDirs*/false ) + aEyeCatcher;
376
378
379 return aName + aGuid.getOUString() + ".tmp" ;
380}
381
383{
384 OUString aName(CreateTempName_Impl( nullptr, false ));
385
386 // convert to file URL
387 OUString aTmp;
388 if ( !aName.isEmpty() )
389 FileBase::getSystemPathFromFileURL( aName, aTmp );
390 return aTmp;
391}
392
394{
395}
396
398 mxStream(std::move(other.mxStream))
399{
400}
401
403{
404 CloseStream();
405}
406
408{
409 if (!mxStream)
410 {
411 OUString aName = CreateTempNameFast();
412#ifdef _WIN32
413 mxStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY | StreamMode::DELETE_ON_CLOSE));
414#else
415 mxStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY));
416#endif
417 }
418 return mxStream.get();
419}
420
422{
423 if (mxStream)
424 {
425#if !defined _WIN32
426 OUString aName = mxStream->GetFileName();
427#endif
428 mxStream.reset();
429#ifdef _WIN32
430 // On Windows, the file is opened with FILE_FLAG_DELETE_ON_CLOSE, so it will delete as soon as the handle closes.
431 // On other platforms, we need to explicitly delete it.
432#else
433 if (!aName.isEmpty() && (osl::FileBase::getFileURLFromSystemPath(aName, aName) == osl::FileBase::E_None))
434 File::remove(aName);
435#endif
436 }
437}
438
439OUString CreateTempURL( const OUString* pParent, bool bDirectory )
440{
441 return CreateTempName_Impl( pParent, true, bDirectory );
442}
443
444OUString CreateTempURL( std::u16string_view rLeadingChars, bool _bStartWithZero,
445 std::u16string_view pExtension, const OUString* pParent,
446 bool bCreateParentDirs )
447{
448 SequentialTokens t(_bStartWithZero);
449 return lcl_createName( rLeadingChars, t, pExtension, pParent, false,
450 true, true, bCreateParentDirs );
451}
452
453TempFileNamed::TempFileNamed( const OUString* pParent, bool bDirectory )
454 : bIsDirectory( bDirectory )
455 , bKillingFileEnabled( false )
456{
457 aName = CreateTempName_Impl( pParent, true, bDirectory );
458}
459
460TempFileNamed::TempFileNamed( std::u16string_view rLeadingChars, bool _bStartWithZero,
461 std::u16string_view pExtension, const OUString* pParent,
462 bool bCreateParentDirs )
463 : bIsDirectory( false )
464 , bKillingFileEnabled( false )
465{
466 SequentialTokens t(_bStartWithZero);
467 aName = lcl_createName( rLeadingChars, t, pExtension, pParent, false,
468 true, true, bCreateParentDirs );
469}
470
472 aName(std::move(other.aName)), pStream(std::move(other.pStream)), bIsDirectory(other.bIsDirectory),
473 bKillingFileEnabled(other.bKillingFileEnabled)
474{
475 other.bKillingFileEnabled = false;
476}
477
479{
480 if ( !bKillingFileEnabled )
481 return;
482
483 pStream.reset();
484 if ( bIsDirectory )
485 {
487 }
488 else
489 {
490 File::remove( aName );
491 }
492}
493
495{
496 return !aName.isEmpty();
497}
498
500{
501 OUString aTmp;
502 FileBase::getSystemPathFromFileURL(aName, aTmp);
503 return aTmp;
504}
505
506OUString const & TempFileNamed::GetURL() const
507{
508 // if you request the URL, then you presumably want to access this via UCB,
509 // and UCB will want to open the file via a separate file handle, which means
510 // we have to make this file data actually hit disk. We do this here (and not
511 // elsewhere) to make the other (normal) paths fast. Flushing to disk
512 // really slows temp files down.
513 if (pStream)
514 pStream->Flush();
515 return aName;
516}
517
519{
520 if (!pStream)
521 {
522 if (!aName.isEmpty())
523 pStream.reset(new SvFileStream(aName, eMode | StreamMode::TEMPORARY));
524 else
525 pStream.reset(new SvMemoryStream);
526 }
527
528 return pStream.get();
529}
530
532{
533 pStream.reset();
534}
535
536OUString SetTempNameBaseDirectory( const OUString &rBaseName )
537{
538 if( rBaseName.isEmpty() )
539 return OUString();
540
541 OUString aUnqPath( rBaseName );
542
543 // remove trailing slash
544 if ( rBaseName.endsWith("/") )
545 aUnqPath = rBaseName.copy( 0, rBaseName.getLength() - 1 );
546
547 // try to create the directory
548 bool bRet = false;
549 osl::FileBase::RC err = osl::Directory::create( aUnqPath );
550 if ( err != FileBase::E_None && err != FileBase::E_EXIST )
551 // perhaps parent(s) don't exist
552 bRet = ensuredir( aUnqPath );
553 else
554 bRet = true;
555
556 // failure to create base directory means returning an empty string
557 OUString aTmp;
558 if ( bRet )
559 {
560 // append own internal directory
561 OUString &rTempNameBase_Impl = gTempNameBase_Impl;
562 rTempNameBase_Impl = rBaseName + "/";
563
564 TempFileNamed aBase( {}, true );
565 if ( aBase.IsValid() )
566 // use it in case of success
567 rTempNameBase_Impl = aBase.aName;
568
569 // return system path of used directory
570 FileBase::getSystemPathFromFileURL( rTempNameBase_Impl, aTmp );
571 }
572
573 return aTmp;
574}
575
577{
578 return ConstructTempDir_Impl(nullptr, false);
579}
580
581
583: mbInClosed( false )
584, mbOutClosed( false )
585{
586 mpTempFile.emplace();
587 mpStream = mpTempFile->GetStream(StreamMode::READWRITE);
588}
589
591{
592}
593
594// XInputStream
595
596sal_Int32 SAL_CALL TempFileFastService::readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
597{
598 std::unique_lock aGuard( maMutex );
599 if ( mbInClosed )
600 throw css::io::NotConnectedException ( OUString(), getXWeak() );
601
603 if (nBytesToRead < 0)
604 throw css::io::BufferSizeExceededException( OUString(), getXWeak());
605
606 if (aData.getLength() < nBytesToRead)
607 aData.realloc(nBytesToRead);
608
609 sal_uInt32 nRead = mpStream->ReadBytes(static_cast<void*>(aData.getArray()), nBytesToRead);
610 checkError();
611
612 if (nRead < o3tl::make_unsigned(aData.getLength()))
613 aData.realloc( nRead );
614
615 return nRead;
616}
617
618sal_Int32 SAL_CALL TempFileFastService::readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
619{
620 {
621 std::unique_lock aGuard( maMutex );
622 if ( mbInClosed )
623 throw css::io::NotConnectedException ( OUString(), getXWeak() );
624
626 checkError();
627
628 if (nMaxBytesToRead < 0)
629 throw css::io::BufferSizeExceededException( OUString(), getXWeak() );
630
631 if (mpStream->eof())
632 {
633 aData.realloc(0);
634 return 0;
635 }
636 }
637 return readBytes(aData, nMaxBytesToRead);
638}
639
640void SAL_CALL TempFileFastService::skipBytes( sal_Int32 nBytesToSkip )
641{
642 std::unique_lock aGuard( maMutex );
643 if ( mbInClosed )
644 throw css::io::NotConnectedException ( OUString(), getXWeak() );
645
647 checkError();
648 mpStream->SeekRel(nBytesToSkip);
649 checkError();
650}
651
653{
654 std::unique_lock aGuard( maMutex );
655 if ( mbInClosed )
656 throw css::io::NotConnectedException ( OUString(), getXWeak() );
657
659
660 sal_Int64 nAvailable = mpStream->remainingSize();
661 checkError();
662
663 return std::min<sal_Int64>(SAL_MAX_INT32, nAvailable);
664}
665
667{
668 std::unique_lock aGuard( maMutex );
669 if ( mbInClosed )
670 throw css::io::NotConnectedException ( OUString(), getXWeak() );
671
672 mbInClosed = true;
673
674 if ( mbOutClosed )
675 {
676 // stream will be deleted by TempFile implementation
677 mpStream = nullptr;
678 mpTempFile.reset();
679 }
680}
681
682// XOutputStream
683
684void SAL_CALL TempFileFastService::writeBytes( const css::uno::Sequence< sal_Int8 >& aData )
685{
686 std::unique_lock aGuard( maMutex );
687 if ( mbOutClosed )
688 throw css::io::NotConnectedException ( OUString(), getXWeak() );
689
691 sal_uInt32 nWritten = mpStream->WriteBytes(aData.getConstArray(), aData.getLength());
692 checkError();
693 if ( nWritten != static_cast<sal_uInt32>(aData.getLength()))
694 throw css::io::BufferSizeExceededException( OUString(), getXWeak() );
695}
696
698{
699 std::unique_lock aGuard( maMutex );
700 if ( mbOutClosed )
701 throw css::io::NotConnectedException ( OUString(), getXWeak() );
702
704 mpStream->Flush();
705 checkError();
706}
707
709{
710 std::unique_lock aGuard( maMutex );
711 if ( mbOutClosed )
712 throw css::io::NotConnectedException ( OUString(), getXWeak() );
713
714 mbOutClosed = true;
715 if (mpStream)
716 {
717 // so that if you then open the InputStream, you can read the content
719 mpStream->Seek(0);
720 }
721
722 if ( mbInClosed )
723 {
724 // stream will be deleted by TempFile implementation
725 mpStream = nullptr;
726 mpTempFile.reset();
727 }
728}
729
731{
732 if (!mpStream || mpStream->SvStream::GetError () != ERRCODE_NONE )
733 throw css::io::NotConnectedException ( OUString(), const_cast < TempFileFastService * > (this)->getXWeak() );
734}
735
737{
738 if (!mpStream)
739 throw css::io::NotConnectedException ( OUString(), getXWeak() );
740}
741
742// XSeekable
743
744void SAL_CALL TempFileFastService::seek( sal_Int64 nLocation )
745{
746 std::unique_lock aGuard( maMutex );
748 checkError();
749 if ( nLocation < 0 )
750 throw css::lang::IllegalArgumentException();
751
752 sal_Int64 nNewLoc = mpStream->Seek(static_cast<sal_uInt32>(nLocation) );
753 if ( nNewLoc != nLocation )
754 throw css::lang::IllegalArgumentException();
755 checkError();
756}
757
759{
760 std::unique_lock aGuard( maMutex );
762
763 sal_uInt32 nPos = mpStream->Tell();
764 checkError();
765 return static_cast<sal_Int64>(nPos);
766}
767
769{
770 std::unique_lock aGuard( maMutex );
772
773 checkError();
774
775 sal_Int64 nEndPos = mpStream->TellEnd();
776
777 return nEndPos;
778}
779
780// XStream
781
782css::uno::Reference< css::io::XInputStream > SAL_CALL TempFileFastService::getInputStream()
783{
784 return this;
785}
786
787css::uno::Reference< css::io::XOutputStream > SAL_CALL TempFileFastService::getOutputStream()
788{
789 return this;
790}
791
792// XTruncate
793
795{
796 std::unique_lock aGuard( maMutex );
798 // SetStreamSize() call does not change the position
799 mpStream->Seek( 0 );
801 checkError();
802}
803
804
805
806}
807
808/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
sal_uInt64 Tell() const
virtual sal_uInt64 TellEnd()
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool eof() const
bool SetStreamSize(sal_uInt64 nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
void Flush()
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 SeekRel(sal_Int64 nPos)
void FlushBuffer()
sal_uInt64 remainingSize()
static bool deleteDirRecursively(const OUString &rDirURL)
OUString getOUString()
static sal_uInt64 GetSystemTicks()
virtual ::sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< ::sal_Int8 > &aData, ::sal_Int32 nMaxBytesToRead) override
Definition: tempfile.cxx:618
virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream() override
Definition: tempfile.cxx:787
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream() override
Definition: tempfile.cxx:782
virtual ::sal_Int32 SAL_CALL readBytes(css::uno::Sequence< ::sal_Int8 > &aData, ::sal_Int32 nBytesToRead) override
Definition: tempfile.cxx:596
virtual void SAL_CALL seek(sal_Int64 location) override
Definition: tempfile.cxx:744
virtual sal_Int64 SAL_CALL getLength() override
Definition: tempfile.cxx:768
virtual void SAL_CALL flush() override
Definition: tempfile.cxx:697
std::optional< utl::TempFileFast > mpTempFile
Definition: tempfile.hxx:202
virtual void SAL_CALL skipBytes(::sal_Int32 nBytesToSkip) override
Definition: tempfile.cxx:640
virtual ~TempFileFastService() override
Definition: tempfile.cxx:590
virtual void SAL_CALL closeInput() override
Definition: tempfile.cxx:666
virtual void SAL_CALL writeBytes(const css::uno::Sequence< ::sal_Int8 > &aData) override
Definition: tempfile.cxx:684
virtual sal_Int64 SAL_CALL getPosition() override
Definition: tempfile.cxx:758
void checkError() const
Definition: tempfile.cxx:730
virtual ::sal_Int32 SAL_CALL available() override
Definition: tempfile.cxx:652
virtual void SAL_CALL truncate() override
Definition: tempfile.cxx:794
virtual void SAL_CALL closeOutput() override
Definition: tempfile.cxx:708
This is the "fast" temp file.
Definition: tempfile.hxx:47
SvStream * GetStream(StreamMode eMode)
Returns a stream to the tempfiles data; the stream is owned by the tempfile object,...
Definition: tempfile.cxx:407
std::unique_ptr< SvFileStream > mxStream
Definition: tempfile.hxx:48
void CloseStream()
Close and destroy the owned stream object if any.
Definition: tempfile.cxx:421
The class TempFile gives access to temporary files in the local file system.
Definition: tempfile.hxx:120
std::unique_ptr< SvStream > pStream
Definition: tempfile.hxx:124
bool IsValid() const
Returns sal_True if it has a valid file name.
Definition: tempfile.cxx:494
SvStream * GetStream(StreamMode eMode)
Returns a stream to the tempfiles data; the stream is owned by the tempfile object,...
Definition: tempfile.cxx:518
~TempFileNamed()
TempFile will be removed from disk in dtor if EnableKillingFile(true) was called before.
Definition: tempfile.cxx:478
OUString const & GetURL() const
Returns the URL of the tempfile object.
Definition: tempfile.cxx:506
void CloseStream()
Let the TempFile object close and destroy the owned stream object if any.
Definition: tempfile.cxx:531
TempFileNamed(const OUString *pParent=nullptr, bool bDirectory=false)
Create a temporary file or directory, in the default tempfile folder or if possible in a given folder...
Definition: tempfile.cxx:453
OUString GetFileName() const
Returns the system path name of the tempfile in host notation If you want to have the URL,...
Definition: tempfile.cxx:499
#define DBG_ASSERT(sCon, aError)
float v
float u
#define max(a, b)
#define ERRCODE_NONE
OUString aName
Mode eMode
sal_uInt16 nPos
constexpr OUStringLiteral aData
err
OUString get(TranslateId sContextAndId, const std::locale &loc)
Definition: resmgr.cxx:211
int i
dictionary tokens
FileStatus
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
OUString CreateTempURL(const OUString *pParent, bool bDirectory)
Definition: tempfile.cxx:439
OUString GetTempNameBaseDirectory()
Definition: tempfile.cxx:576
OUString SetTempNameBaseDirectory(const OUString &rBaseName)
The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in th...
Definition: tempfile.cxx:536
static OUString ConstructTempDir_Impl(const OUString *pParent, bool bCreateParentDirs)
Definition: tempfile.cxx:118
static OUString CreateTempName_Impl(const OUString *pParent, bool bKeep, bool bDir=true)
Definition: tempfile.cxx:329
static OUString lcl_createName(std::u16string_view rLeadingChars, Tokens &tokens, std::u16string_view pExtension, const OUString *pParent, bool bDirectory, bool bKeep, bool bLock, bool bCreateParentDirs)
Definition: tempfile.cxx:253
static OUString CreateTempNameFast()
Definition: tempfile.cxx:354
static OUString getParentName(std::u16string_view aFileName)
Definition: tempfile.cxx:55
static bool ensuredir(const OUString &rUnqPath)
Definition: tempfile.cxx:74
OUString CreateTempName()
Only create a "physical" file name for a temporary file that would be valid at that moment.
Definition: tempfile.cxx:382
StreamMode
sal_uInt32 m_value
Definition: tempfile.cxx:197
bool m_show
Definition: tempfile.cxx:198
static sal_uInt32 globalValue
Definition: tempfile.cxx:231
sal_uInt32 m_count
Definition: tempfile.cxx:233
#define SAL_MAX_INT32
#define SAL_MAX_UINT32