bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / file / filrec.cxx
blob5af520bc351d3fefbde3e425c1113353e872538e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "filrec.hxx"
23 namespace fileaccess {
25 void ReconnectingFile::disconnect()
27 m_aFile.close();
28 m_bDisconnect = true;
31 bool ReconnectingFile::reconnect()
33 bool bResult = false;
34 if ( m_bFlagsSet )
36 disconnect();
37 if ( m_aFile.open( m_nFlags ) == ::osl::FileBase::E_None
38 || m_aFile.open( osl_File_OpenFlag_Read ) == ::osl::FileBase::E_None )
40 m_bDisconnect = false;
41 bResult = true;
45 return bResult;
48 ::osl::FileBase::RC ReconnectingFile::open( sal_uInt32 uFlags )
50 ::osl::FileBase::RC nResult = m_aFile.open( uFlags );
51 if ( nResult == ::osl::FileBase::E_None )
53 if ( uFlags & osl_File_OpenFlag_Create )
54 m_nFlags = (uFlags & ( ~osl_File_OpenFlag_Create )) | osl_File_OpenFlag_Write;
55 else
56 m_nFlags = uFlags;
58 m_bFlagsSet = true;
61 return nResult;
64 ::osl::FileBase::RC ReconnectingFile::close()
66 m_nFlags = 0;
67 m_bFlagsSet = false;
68 m_bDisconnect = false;
70 return m_aFile.close();
73 ::osl::FileBase::RC ReconnectingFile::setPos( sal_uInt32 uHow, sal_Int64 uPos )
75 ::osl::FileBase::RC nRes = ::osl::FileBase::E_NETWORK;
77 if ( uHow == osl_Pos_Absolut && uPos > 0 )
79 if ( m_bDisconnect )
81 if ( reconnect() )
82 nRes = m_aFile.setPos( uHow, uPos );
84 else
86 // E_INVAL error code means in this case that
87 // the file handler is invalid
88 nRes = m_aFile.setPos( uHow, uPos );
89 if ( ( nRes == ::osl::FileBase::E_NETWORK
90 || nRes == ::osl::FileBase::E_INVAL )
91 && reconnect() )
92 nRes = m_aFile.setPos( uHow, uPos );
95 else
97 if ( !m_bDisconnect )
98 nRes = m_aFile.setPos( uHow, uPos );
101 return nRes;
104 ::osl::FileBase::RC ReconnectingFile::getPos( sal_uInt64& uPos )
106 if ( m_bDisconnect )
107 return ::osl::FileBase::E_NETWORK;
109 return m_aFile.getPos( uPos );
112 ::osl::FileBase::RC ReconnectingFile::setSize( sal_uInt64 uSize )
114 ::osl::FileBase::RC nRes = ::osl::FileBase::E_NETWORK;
116 if ( uSize == 0 )
118 if ( m_bDisconnect )
120 if ( reconnect() )
121 nRes = m_aFile.setSize( uSize );
123 else
125 // E_INVAL error code means in this case that
126 // the file handler is invalid
127 nRes = m_aFile.setSize( uSize );
128 if ( ( nRes == ::osl::FileBase::E_NETWORK
129 || nRes == ::osl::FileBase::E_INVAL )
130 && reconnect() )
131 nRes = m_aFile.setSize( uSize );
134 else
136 if ( !m_bDisconnect )
137 nRes = m_aFile.setSize( uSize );
140 return nRes;
143 ::osl::FileBase::RC ReconnectingFile::getSize( sal_uInt64 &rSize )
145 ::osl::FileBase::RC nRes = ::osl::FileBase::E_NETWORK;
147 if ( !m_bDisconnect )
148 nRes = m_aFile.getSize( rSize );
150 // E_INVAL error code means in this case that
151 // the file handler is invalid
152 if ( ( nRes == ::osl::FileBase::E_NETWORK
153 || nRes == ::osl::FileBase::E_INVAL )
154 && reconnect() )
156 nRes = m_aFile.getSize( rSize );
158 // the repairing should be disconnected, since the position might be wrong
159 // but the result should be retrieved
160 disconnect();
163 return nRes;
166 ::osl::FileBase::RC ReconnectingFile::read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
168 if ( m_bDisconnect )
169 return ::osl::FileBase::E_NETWORK;
171 return m_aFile.read( pBuffer, uBytesRequested, rBytesRead );
174 ::osl::FileBase::RC ReconnectingFile::write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
176 if ( m_bDisconnect )
177 return ::osl::FileBase::E_NETWORK;
179 return m_aFile.write( pBuffer, uBytesToWrite, rBytesWritten );
182 ::osl::FileBase::RC ReconnectingFile::sync() const
184 if ( m_bDisconnect )
185 return ::osl::FileBase::E_NETWORK;
187 return m_aFile.sync();
190 } // namespace fileaccess
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */