1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: fstat.cxx,v $
*
* $Revision: 1.4 $
*
* last change: $Author: obo $ $Date: 2006-09-17 00:53:29 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_tools.hxx"
#if defined( WIN)
#include <stdio.h>
#include <dos.h>
#endif
#ifdef UNX
#include <errno.h>
#endif
#include <limits.h>
#include <string.h>
#include "comdep.hxx"
#include <fsys.hxx>
/*************************************************************************
|*
|* FileStat::FileStat()
|*
|* Beschreibung FSYS.SDW
|* Ersterstellung MI 11.06.91
|* Letzte Aenderung MI 11.06.91
|*
*************************************************************************/
FileStat::FileStat()
: // don't use Default-Ctors!
aDateCreated( ULONG(0) ),
aTimeCreated( ULONG(0) ),
aDateModified( ULONG(0) ),
aTimeModified( ULONG(0) ),
aDateAccessed( ULONG(0) ),
aTimeAccessed( ULONG(0) )
{
nSize = 0;
nKindFlags = FSYS_KIND_UNKNOWN;
nError = FSYS_ERR_OK;
}
/*************************************************************************
|*
|* FileStat::FileStat()
|*
|* Beschreibung FSYS.SDW
|* Ersterstellung MI 11.06.91
|* Letzte Aenderung MI 11.06.91
|*
*************************************************************************/
FileStat::FileStat( const DirEntry& rDirEntry, FSysAccess nAccess )
: // don't use Default-Ctors!
aDateCreated( ULONG(0) ),
aTimeCreated( ULONG(0) ),
aDateModified( ULONG(0) ),
aTimeModified( ULONG(0) ),
aDateAccessed( ULONG(0) ),
aTimeAccessed( ULONG(0) )
{
BOOL bCached = FSYS_ACCESS_CACHED == (nAccess & FSYS_ACCESS_CACHED);
BOOL bFloppy = FSYS_ACCESS_FLOPPY == (nAccess & FSYS_ACCESS_FLOPPY);
#ifdef FEAT_FSYS_DOUBLESPEED
const FileStat *pStatFromDir = bCached ? rDirEntry.ImpGetStat() : 0;
if ( pStatFromDir )
{
nError = pStatFromDir->nError;
nKindFlags = pStatFromDir->nKindFlags;
nSize = pStatFromDir->nSize;
aCreator = pStatFromDir->aCreator;
aType = pStatFromDir->aType;
aDateCreated = pStatFromDir->aDateCreated;
aTimeCreated = pStatFromDir->aTimeCreated;
aDateModified = pStatFromDir->aDateModified;
aTimeModified = pStatFromDir->aTimeModified;
aDateAccessed = pStatFromDir->aDateAccessed;
aTimeAccessed = pStatFromDir->aTimeAccessed;
}
else
#endif
Update( rDirEntry, bFloppy );
}
/*************************************************************************
|*
|* FileStat::IsYounger()
|*
|* Beschreibung FSYS.SDW
|* Ersterstellung MA 11.11.91
|* Letzte Aenderung MA 11.11.91
|*
*************************************************************************/
// TRUE wenn die Instanz j"unger als rIsOlder ist.
// FALSE wenn die Instanz "alter oder gleich alt wie rIsOlder ist.
BOOL FileStat::IsYounger( const FileStat& rIsOlder ) const
{
if ( aDateModified > rIsOlder.aDateModified )
return TRUE;
if ( ( aDateModified == rIsOlder.aDateModified ) &&
( aTimeModified > rIsOlder.aTimeModified ) )
return TRUE;
return FALSE;
}
/*************************************************************************
|*
|* FileStat::IsKind()
|*
|* Ersterstellung MA 11.11.91 (?)
|* Letzte Aenderung KH 16.01.95
|*
*************************************************************************/
BOOL FileStat::IsKind( DirEntryKind nKind ) const
{
BOOL bRet = ( ( nKind == FSYS_KIND_UNKNOWN ) &&
( nKindFlags == FSYS_KIND_UNKNOWN ) ) ||
( ( nKindFlags & nKind ) == nKind );
return bRet;
}
/*************************************************************************
|*
|* FileStat::HasReadOnlyFlag()
|*
|* Ersterstellung MI 06.03.97
|* Letzte Aenderung UT 01.07.98
|*
*************************************************************************/
BOOL FileStat::HasReadOnlyFlag()
{
#if defined WNT || defined UNX
return TRUE;
#else
return FALSE;
#endif
}
/*************************************************************************
|*
|* FileStat::GetReadOnlyFlag()
|*
|* Ersterstellung MI 06.03.97
|* Letzte Aenderung UT 02.07.98
|*
*************************************************************************/
BOOL FileStat::GetReadOnlyFlag( const DirEntry &rEntry )
{
ByteString aFPath(rEntry.GetFull(), osl_getThreadTextEncoding());
#if defined WNT
DWORD nRes = GetFileAttributes( (LPCTSTR) aFPath.GetBuffer() );
return ULONG_MAX != nRes &&
( FILE_ATTRIBUTE_READONLY & nRes ) == FILE_ATTRIBUTE_READONLY;
#elif defined UNX
/* could we stat the object? */
struct stat aBuf;
if (stat(aFPath.GetBuffer(), &aBuf))
return FALSE;
/* jupp, is writable for user? */
return((aBuf.st_mode & S_IWUSR) != S_IWUSR);
#else
return FALSE;
#endif
}
/*************************************************************************
|*
|* FileStat::SetReadOnlyFlag()
|*
|* Ersterstellung MI 06.03.97
|* Letzte Aenderung UT 01.07.98
|*
*************************************************************************/
ULONG FileStat::SetReadOnlyFlag( const DirEntry &rEntry, BOOL bRO )
{
ByteString aFPath(rEntry.GetFull(), osl_getThreadTextEncoding());
#if defined WNT
DWORD nRes = GetFileAttributes( (LPCTSTR) aFPath.GetBuffer() );
if ( ULONG_MAX != nRes )
nRes = SetFileAttributes( (LPCTSTR) aFPath.GetBuffer(),
( nRes & ~FILE_ATTRIBUTE_READONLY ) |
( bRO ? FILE_ATTRIBUTE_READONLY : 0 ) );
return ( ULONG_MAX == nRes ) ? ERRCODE_IO_UNKNOWN : 0;
#elif defined UNX
/* first, stat the object to get permissions */
struct stat aBuf;
if (stat(aFPath.GetBuffer(), &aBuf))
return ERRCODE_IO_NOTEXISTS;
/* set or clear write bit for user */
mode_t nMode;
if (bRO)
{
nMode = aBuf.st_mode & ~S_IWUSR;
nMode = aBuf.st_mode & ~S_IWGRP;
nMode = aBuf.st_mode & ~S_IWOTH;
}
else
nMode = aBuf.st_mode | S_IWUSR;
/* change it on fs */
if (chmod(aFPath.GetBuffer(), nMode))
{
switch (errno)
{
case EPERM :
case EROFS :
return ERRCODE_IO_ACCESSDENIED;
default :
return ERRCODE_IO_NOTEXISTS;
}
}
else
return ERRCODE_NONE;
#else
return ERRCODE_IO_NOTSUPPORTED;
#endif
}
/*************************************************************************
|*
|* FileStat::SetDateTime
|*
|* Ersterstellung PB 27.06.97
|* Letzte Aenderung
|*
*************************************************************************/
#if defined WNT
void FileStat::SetDateTime( const String& rFileName,
const DateTime& rNewDateTime )
{
ByteString aFileName(rFileName, osl_getThreadTextEncoding());
Date aNewDate = rNewDateTime;
Time aNewTime = rNewDateTime;
TIME_ZONE_INFORMATION aTZI;
DWORD dwTZI = GetTimeZoneInformation( &aTZI );
if ( dwTZI != (DWORD)-1 && dwTZI != TIME_ZONE_ID_UNKNOWN )
{
// 1. Korrektur der Zeitzone
LONG nDiff = aTZI.Bias;
Time aOldTime = aNewTime; // alte Zeit merken
// 2. evt. Korrektur Sommer-/Winterzeit
if ( dwTZI == TIME_ZONE_ID_DAYLIGHT )
nDiff += aTZI.DaylightBias;
Time aDiff( abs( nDiff / 60 /*Min -> Std*/ ), 0 );
if ( nDiff > 0 )
{
aNewTime += aDiff; // Stundenkorrektur
// bei "Uberlauf korrigieren
if ( aNewTime >= Time( 24, 0 ) )
aNewTime -= Time( 24, 0 );
// Tages"uberlauf?
if ( aOldTime == Time( 0, 0 ) || // 00:00 -> 01:00
aNewTime < aOldTime ) // 23:00 -> 00:00 | 01:00 ...
aNewDate++;
}
else if ( nDiff < 0 )
{
aNewTime -= aDiff; // Stundenkorrektur
// negative Zeit (-1:00) korrigieren: 23:00
if (aNewTime < Time( 0, 0 ) )
aNewTime += Time( 24, 0 );
// Tagesunterlauf ?
if ( aOldTime == Time( 0, 0 ) || // 00:00 -> 23:00
aNewTime > aOldTime ) // 01:00 -> 23:00 | 22:00 ...
aNewDate--;
}
}
SYSTEMTIME aTime;
aTime.wYear = aNewDate.GetYear();
aTime.wMonth = aNewDate.GetMonth();
aTime.wDayOfWeek = 0;
aTime.wDay = aNewDate.GetDay();
aTime.wHour = aNewTime.GetHour();
aTime.wMinute = aNewTime.GetMin();
aTime.wSecond = aNewTime.GetSec();
aTime.wMilliseconds = 0;
FILETIME aFileTime;
SystemTimeToFileTime( &aTime, &aFileTime );
HANDLE hFile = CreateFile( aFileName.GetBuffer(), GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if ( hFile != INVALID_HANDLE_VALUE )
{
SetFileTime( hFile, &aFileTime, &aFileTime, &aFileTime );
CloseHandle( hFile );
}
}
#endif
|