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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_OSL_FILE_HXX
#define INCLUDED_OSL_FILE_HXX
#include "sal/config.h"
#include <string.h>
#include <cassert>
#include <cstddef>
#include "sal/log.hxx"
#include "osl/time.h"
#include "rtl/ustring.hxx"
#include "osl/file.h"
#include "osl/diagnose.h"
#include "rtl/byteseq.hxx"
#include <stdio.h>
namespace osl
{
/** Base class for all File System specific objects.
@see Directory
@see DirectoryItem
@see File
*/
class FileBase
{
public:
enum RC {
E_None = osl_File_E_None, ///< on success
E_PERM = osl_File_E_PERM, ///< operation not permitted
E_NOENT = osl_File_E_NOENT, ///< no such file or directory
E_SRCH = osl_File_E_SRCH, ///< no process matches the PID
E_INTR = osl_File_E_INTR, ///< function call was interrupted
E_IO = osl_File_E_IO, ///< I/O error occurred
E_NXIO = osl_File_E_NXIO, ///< no such device or address
E_2BIG = osl_File_E_2BIG, ///< argument list too long
E_NOEXEC = osl_File_E_NOEXEC, ///< invalid executable file format
E_BADF = osl_File_E_BADF, ///< bad file descriptor
E_CHILD = osl_File_E_CHILD, ///< there are no child processes
E_AGAIN = osl_File_E_AGAIN, ///< resource temp unavailable, try again later
E_NOMEM = osl_File_E_NOMEM, ///< no memory available
E_ACCES = osl_File_E_ACCES, ///< file permissions do not allow operation
E_FAULT = osl_File_E_FAULT, ///< bad address; an invalid pointer detected
E_BUSY = osl_File_E_BUSY, ///< resource busy
E_EXIST = osl_File_E_EXIST, ///< file exists where should only be created
E_XDEV = osl_File_E_XDEV, ///< improper link across file systems detected
E_NODEV = osl_File_E_NODEV, ///< wrong device type specified
E_NOTDIR = osl_File_E_NOTDIR, ///< file isn't a directory where one is needed
E_ISDIR = osl_File_E_ISDIR, ///< file is a directory, invalid operation
E_INVAL = osl_File_E_INVAL, ///< invalid argument to library function
E_NFILE = osl_File_E_NFILE, ///< too many distinct file openings
E_MFILE = osl_File_E_MFILE, ///< process has too many distinct files open
E_NOTTY = osl_File_E_NOTTY, ///< inappropriate I/O control operation
E_FBIG = osl_File_E_FBIG, ///< file too large
E_NOSPC = osl_File_E_NOSPC, ///< no space left on device, write failed
E_SPIPE = osl_File_E_SPIPE, ///< invalid seek operation (such as on pipe)
E_ROFS = osl_File_E_ROFS, ///< illegal modification to read-only filesystem
E_MLINK = osl_File_E_MLINK, ///< too many links to file
E_PIPE = osl_File_E_PIPE, ///< broken pipe; no process reading from other end of pipe
E_DOM = osl_File_E_DOM, ///< domain error (mathematical error)
E_RANGE = osl_File_E_RANGE, ///< range error (mathematical error)
E_DEADLK = osl_File_E_DEADLK, ///< deadlock avoided
E_NAMETOOLONG = osl_File_E_NAMETOOLONG, ///< filename too long
E_NOLCK = osl_File_E_NOLCK, ///< no locks available
E_NOSYS = osl_File_E_NOSYS, ///< function not implemented
E_NOTEMPTY = osl_File_E_NOTEMPTY, ///< directory not empty
E_LOOP = osl_File_E_LOOP, ///< too many levels of symbolic links found during name lookup
E_ILSEQ = osl_File_E_ILSEQ, ///< invalid or incomplete byte sequence of multibyte char found
E_NOLINK = osl_File_E_NOLINK, ///< link has been severed
E_MULTIHOP = osl_File_E_MULTIHOP, ///< remote resource is not directly available
E_USERS = osl_File_E_USERS, ///< file quote system is confused as there are too many users
E_OVERFLOW = osl_File_E_OVERFLOW, ///< value too large for defined data type
E_NOTREADY = osl_File_E_NOTREADY, ///< device not ready
E_invalidError = osl_File_E_invalidError, ///< unmapped error: always last entry in enum!
E_TIMEDOUT = osl_File_E_TIMEDOUT, ///< socket operation timed out
E_NETWORK = osl_File_E_NETWORK
};
public:
/** Determine a valid unused canonical name for a requested name.
Determines a valid unused canonical name for a requested name.
Depending on the Operating System and the File System the illegal characters are replaced by valid ones.
If a file or directory with the requested name already exists a new name is generated following
the common rules on the actual Operating System and File System.
@param[in] ustrRequestedURL
Requested name of a file or directory.
@param[out] ustrValidURL
On success receives a name which is unused and valid on the actual Operating System and
File System.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@see DirectoryItem::getFileStatus()
*/
static RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
{
return static_cast< RC >( osl_getCanonicalName( ustrRequestedURL.pData, &ustrValidURL.pData ) );
}
/** Convert a path relative to a given directory into an full qualified file URL.
Convert a path relative to a given directory into an full qualified file URL.
The function resolves symbolic links if possible and path ellipses, so on success
the resulting absolute path is fully resolved.
@param[in] ustrBaseDirectoryURL
Base directory URL to which the relative path is related to.
@param[in] ustrRelativeFileURL
An URL of a file or directory relative to the directory path specified by ustrBaseDirectoryURL
or an absolute path.
If ustrRelativeFileURL denotes an absolute path ustrBaseDirectoryURL will be ignored.
@param[out] ustrAbsoluteFileURL
On success it receives the full qualified absolute file URL.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_NOTDIR not a directory
@retval E_ACCES permission denied
@retval E_NOENT no such file or directory
@retval E_NAMETOOLONG file name too long
@retval E_OVERFLOW value too large for defined data type
@retval E_FAULT bad address
@retval E_INTR function call was interrupted
@retval E_LOOP too many symbolic links encountered
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@see DirectoryItem::getFileStatus()
*/
static RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, const ::rtl::OUString& ustrRelativeFileURL, ::rtl::OUString& ustrAbsoluteFileURL )
{
return static_cast< RC >( osl_getAbsoluteFileURL( ustrBaseDirectoryURL.pData, ustrRelativeFileURL.pData, &ustrAbsoluteFileURL.pData ) );
}
/** Convert a file URL into a system dependent path.
@param[in] ustrFileURL
A File URL.
@param[out] ustrSystemPath
On success it receives the system path.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@see getFileURLFromSystemPath()
*/
static RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, ::rtl::OUString& ustrSystemPath )
{
return static_cast< RC >( osl_getSystemPathFromFileURL( ustrFileURL.pData, &ustrSystemPath.pData ) );
}
/** Convert a system dependent path into a file URL.
@param[in] ustrSystemPath
A System dependent path of a file or directory.
@param[out] ustrFileURL
On success it receives the file URL.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@see getSystemPathFromFileURL()
*/
static RC getFileURLFromSystemPath( const ::rtl::OUString& ustrSystemPath, ::rtl::OUString& ustrFileURL )
{
return static_cast< RC >( osl_getFileURLFromSystemPath( ustrSystemPath.pData, &ustrFileURL.pData ) );
}
/** Searche a full qualified system path or a file URL.
@param[in] ustrFileName
A system dependent path, a file URL, a file or relative directory
@param[in] ustrSearchPath
A list of system paths, in which a given file has to be searched. The Notation of a path list is
system dependent, e.g. on UNIX system "/usr/bin:/bin" and on Windows "C:\BIN;C:\BATCH".
These paths are only for the search of a file or a relative path, otherwise it will be ignored.
If ustrSearchPath is NULL or while using the search path the search failed, the function searches for
a matching file in all system directories and in the directories listed in the PATH environment
variable.
The value of an environment variable should be used (e.g. LD_LIBRARY_PATH) if the caller is not
aware of the Operating System and so doesn't know which path list delimiter to use.
@param[out] ustrFileURL
On success it receives the full qualified file URL.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOTDIR not a directory
@retval E_NOENT no such file or directory not found
@see getFileURLFromSystemPath()
@see getSystemPathFromFileURL()
*/
static RC searchFileURL( const ::rtl::OUString& ustrFileName, const ::rtl::OUString& ustrSearchPath, ::rtl::OUString& ustrFileURL )
{
return static_cast< RC >( osl_searchFileURL( ustrFileName.pData, ustrSearchPath.pData, &ustrFileURL.pData ) );
}
/** Retrieves the file URL of the system's temporary directory path.
@param[out] ustrTempDirURL
On success receives the URL of system's temporary directory path.
@retval E_None on success
@retval E_NOENT no such file or directory not found
*/
static RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
{
return static_cast< RC >( osl_getTempDirURL( &ustrTempDirURL.pData ) );
}
/** Creates a temporary file in the directory provided by the caller or the
directory returned by getTempDirURL.
Under UNIX Operating Systems the file will be created with read and write
access for the user exclusively.
If the caller requests only a handle to the open file but not the name of
it, the file will be automatically removed on close else the caller is
responsible for removing the file on success.<br><br>
@param[in] pustrDirectoryURL
Specifies the full qualified URL where the temporary file should be created.
If pustrDirectoryURL is 0 the path returned by osl_getTempDirURL will be used.
@param[out] pHandle
On success receives a handle to the open file.
If pHandle is 0 the file will be closed on return, in this case
pustrTempFileURL must not be 0.
@param[out] pustrTempFileURL
On success receives the full qualified URL of the temporary file.
If pustrTempFileURL is 0 the file will be automatically removed
on close, in this case pHandle must not be 0.
If pustrTempFileURL is not 0 the caller receives the name of the
created file and is responsible for removing the file.
Description of the different pHandle, ppustrTempFileURL parameter combinations.
pHandle is 0 and pustrTempDirURL is 0 - this combination is invalid<br>
pHandle is not 0 and pustrTempDirURL is 0 - a handle to the open file
will be returned on success and the file will be automatically removed on close<br>
pHandle is 0 and pustrTempDirURL is not 0 - the name of the file will be
returned, the caller is responsible for opening, closing and removing the file.<br>
pHandle is not 0 and pustrTempDirURL is not 0 - a handle to the open file as well as
the file name will be returned, the caller is responsible for closing and removing
the file.<br>
@retval E_None on success
@retval E_INVAL the format of the parameter is invalid
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES Permission denied
@retval E_NOENT No such file or directory
@retval E_NOTDIR Not a directory
@retval E_ROFS Read-only file system
@retval E_NOSPC No space left on device
@retval E_DQUOT Quota exceeded
@see getTempDirURL()
*/
static RC createTempFile(
::rtl::OUString* pustrDirectoryURL,
oslFileHandle* pHandle,
::rtl::OUString* pustrTempFileURL)
{
rtl_uString* pustr_dir_url = pustrDirectoryURL ? pustrDirectoryURL->pData : NULL;
rtl_uString** ppustr_tmp_file_url = pustrTempFileURL ? &pustrTempFileURL->pData : NULL;
return static_cast< RC >( osl_createTempFile(pustr_dir_url, pHandle, ppustr_tmp_file_url) );
}
};
/** The VolumeDevice class.
@see VolumeInfo
*/
class VolumeDevice : public FileBase
{
oslVolumeDeviceHandle _aHandle;
public:
/** Constructor.
*/
VolumeDevice() : _aHandle( NULL )
{
}
/** Copy constructor.
@param rDevice
The other volume device.
*/
VolumeDevice( const VolumeDevice & rDevice )
{
_aHandle = rDevice._aHandle;
if ( _aHandle )
osl_acquireVolumeDeviceHandle( _aHandle );
}
/** Destructor.
*/
~VolumeDevice()
{
if ( _aHandle )
osl_releaseVolumeDeviceHandle( _aHandle );
}
/** Assignment operator.
@param rDevice
The other volume device.
*/
VolumeDevice & operator =( const VolumeDevice & rDevice )
{
oslVolumeDeviceHandle newHandle = rDevice._aHandle;
if ( newHandle )
osl_acquireVolumeDeviceHandle( newHandle );
if ( _aHandle )
osl_releaseVolumeDeviceHandle( _aHandle );
_aHandle = newHandle;
return *this;
}
/** Get the full qualified URL where a device is mounted to.
@return
The full qualified URL where the device is mounted to.
*/
rtl::OUString getMountPath()
{
rtl::OUString aPath;
osl_getVolumeDeviceMountPath( _aHandle, &aPath.pData );
return aPath;
}
friend class VolumeInfo;
};
class Directory;
/** The VolumeInfo class.
Neither copy nor assignment is allowed for this class.
@see Directory::getVolumeInfo
*/
class VolumeInfo
{
oslVolumeInfo _aInfo;
sal_uInt32 _nMask;
VolumeDevice _aDevice;
/** Copy constructor.
*/
VolumeInfo( VolumeInfo& ) SAL_DELETED_FUNCTION;
/** Assignment operator.
*/
VolumeInfo& operator = ( VolumeInfo& ) SAL_DELETED_FUNCTION;
public:
/** Constructor.
@param nMask
Set of flags describing the demanded information.
*/
VolumeInfo( sal_uInt32 nMask )
: _nMask( nMask )
{
memset( &_aInfo, 0, sizeof( oslVolumeInfo ));
_aInfo.uStructSize = sizeof( oslVolumeInfo );
_aInfo.pDeviceHandle = &_aDevice._aHandle;
}
~VolumeInfo()
{
if( _aInfo.ustrFileSystemName )
rtl_uString_release( _aInfo.ustrFileSystemName );
}
/** Check if specified fields are valid.
@param nMask
Set of flags for the fields to check.
@return true if all fields are valid else false.
*/
bool isValid( sal_uInt32 nMask ) const
{
return ( nMask & _aInfo.uValidFields ) == nMask;
}
/** Check the remote flag.
@return
true if Attributes are valid and the volume is remote else false.
*/
bool getRemoteFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_Remote) != 0;
}
/** Check the removable flag.
@return
true if attributes are valid and the volume is removable else false.
*/
bool getRemoveableFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_Removeable) != 0;
}
/** Check the compact disc flag.
@return
true if attributes are valid and the volume is a CDROM else false.
*/
bool getCompactDiscFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_CompactDisc) != 0;
}
/** Check the floppy disc flag.
@return
true if attributes are valid and the volume is a floppy disk else false.
*/
bool getFloppyDiskFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_FloppyDisk) != 0;
}
/** Check the fixed disk flag.
@return
true if attributes are valid and the volume is a fixed disk else false.
*/
bool getFixedDiskFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_FixedDisk) != 0;
}
/** Check the RAM disk flag.
@return
true if attributes are valid and the volume is a RAM disk else false.
*/
bool getRAMDiskFlag() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_RAMDisk) != 0;
}
/** Determine the total space of a volume device.
@return
The total diskspace of this volume if this information is valid,
0 otherwise.
*/
sal_uInt64 getTotalSpace() const
{
return _aInfo.uTotalSpace;
}
/** Determine the free space of a volume device.
@return
The free diskspace of this volume if this information is valid,
0 otherwise.
*/
sal_uInt64 getFreeSpace() const
{
return _aInfo.uFreeSpace;
}
/** Determine the used space of a volume device.
@return
The used diskspace of this volume if this information is valid,
0 otherwise.
*/
sal_uInt64 getUsedSpace() const
{
return _aInfo.uUsedSpace;
}
/** Determine the maximal length of a file name.
@return
The maximal length of a file name if this information is valid,
0 otherwise.
*/
sal_uInt32 getMaxNameLength() const
{
return _aInfo.uMaxNameLength;
}
/** Determine the maximal length of a path name.
@return
The maximal length of a path if this information is valid,
0 otherwise.
*/
sal_uInt32 getMaxPathLength() const
{
return _aInfo.uMaxPathLength;
}
/** Determine the name of the volume device's File System.
@return
The name of the volume's filesystem if this information is valid,
otherwise an empty string.
*/
::rtl::OUString getFileSystemName() const
{
return _aInfo.ustrFileSystemName ? ::rtl::OUString( _aInfo.ustrFileSystemName ) : ::rtl::OUString();
}
/** Get the volume device handle.
@return
The device handle of the volume if this information is valid,
otherwise returns NULL;
*/
VolumeDevice getDeviceHandle() const
{
return _aDevice;
}
/** Return whether the file system is case sensitive or
case insensitive
@return
true if the file system is case sensitive false otherwise
*/
bool isCaseSensitiveFileSystem() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Sensitive) != 0;
}
/** Return whether the file system preserves the case of
file and directory names or not
@return
true if the file system preserves the case of file and
directory names false otherwise
*/
bool isCasePreservingFileSystem() const
{
return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Is_Preserved) != 0;
}
friend class Directory;
};
class DirectoryItem;
/** The FileStatus class.
@see DirectoryItem::getFileStatus
*/
class FileStatus
{
oslFileStatus _aStatus;
sal_uInt32 _nMask;
/** Copy constructor.
*/
FileStatus( FileStatus& ) SAL_DELETED_FUNCTION;
/** Assignment operator.
*/
FileStatus& operator = ( FileStatus& ) SAL_DELETED_FUNCTION;
public:
enum Type {
Directory = osl_File_Type_Directory,
Volume = osl_File_Type_Volume,
Regular = osl_File_Type_Regular,
Fifo = osl_File_Type_Fifo,
Socket = osl_File_Type_Socket,
Link = osl_File_Type_Link,
Special = osl_File_Type_Special,
Unknown = osl_File_Type_Unknown
};
/** Constructor.
@param nMask
Set of flags describing the demanded information.
*/
FileStatus(sal_uInt32 nMask)
: _nMask(nMask)
{
memset(&_aStatus, 0, sizeof(_aStatus));
_aStatus.uStructSize = sizeof(_aStatus);
}
/** Destructor.
*/
~FileStatus()
{
if ( _aStatus.ustrFileURL )
rtl_uString_release( _aStatus.ustrFileURL );
if ( _aStatus.ustrLinkTargetURL )
rtl_uString_release( _aStatus.ustrLinkTargetURL );
if ( _aStatus.ustrFileName )
rtl_uString_release( _aStatus.ustrFileName );
}
/** Check if specified fields are valid.
@param nMask
Set of flags for the fields to check.
@return
true if all fields are valid else false.
*/
bool isValid( sal_uInt32 nMask ) const
{
return ( nMask & _aStatus.uValidFields ) == nMask;
}
/** Get the file type.
@return
The file type.
*/
Type getFileType() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_Type), "sal.osl",
"no FileStatus Type determined");
return isValid(osl_FileStatus_Mask_Type)
? static_cast< Type >(_aStatus.eType) : Unknown;
}
/** Is it a directory?
This method returns True for both directories, and volumes.
@return
True if it's a directory, False otherwise.
@see getFileType
@since LibreOffice 3.6
*/
bool isDirectory() const
{
return ( getFileType() == Directory || getFileType() == Volume );
}
/** Is it a regular file?
@return
True if it's a regular file, False otherwise.
@see getFileType
@see isFile
@see isLink
@since LibreOffice 3.6
*/
bool isRegular() const
{
return ( getFileType() == Regular );
}
/** Is it a link?
@return
True if it's a link, False otherwise.
@see getFileType
@since LibreOffice 3.6
*/
bool isLink() const
{
return ( getFileType() == Link );
}
/** Get the file attributes.
@return
The set of attribute flags of this file.
*/
sal_uInt64 getAttributes() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_Attributes), "sal.osl",
"no FileStatus Attributes determined");
return _aStatus.uAttributes;
}
/** Get the creation time of this file.
@return
The creation time if this information is valid, an uninitialized
TimeValue otherwise.
*/
TimeValue getCreationTime() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_CreationTime), "sal.osl",
"no FileStatus CreationTime determined");
return _aStatus.aCreationTime;
}
/** Get the file access time.
@return
The last access time if this information is valid, an uninitialized
TimeValue otherwise.
*/
TimeValue getAccessTime() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_AccessTime), "sal.osl",
"no FileStatus AccessTime determined");
return _aStatus.aAccessTime;
}
/** Get the file modification time.
@return
The last modified time if this information is valid, an uninitialized
TimeValue otherwise.
*/
TimeValue getModifyTime() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_ModifyTime), "sal.osl",
"no FileStatus ModifyTime determined");
return _aStatus.aModifyTime;
}
/** Get the size of the file.
@return
The actual file size if this information is valid, 0 otherwise.
*/
sal_uInt64 getFileSize() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_FileSize), "sal.osl",
"no FileStatus FileSize determined");
return _aStatus.uFileSize;
}
/** Get the file name.
@return
The file name if this information is valid, an empty string otherwise.
*/
::rtl::OUString getFileName() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_FileName), "sal.osl",
"no FileStatus FileName determined");
return isValid(osl_FileStatus_Mask_FileName)
? rtl::OUString(_aStatus.ustrFileName) : rtl::OUString();
}
/** Get the URL of the file.
@return
The full qualified URL of the file if this information is valid, an
empty string otherwise.
*/
::rtl::OUString getFileURL() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_FileURL), "sal.osl",
"no FileStatus FileURL determined");
return isValid(osl_FileStatus_Mask_FileURL)
? rtl::OUString(_aStatus.ustrFileURL) : rtl::OUString();
}
/** Get the link target URL.
@return
The link target URL if this information is valid, an empty string
otherwise.
*/
::rtl::OUString getLinkTargetURL() const
{
SAL_INFO_IF(
!isValid(osl_FileStatus_Mask_LinkTargetURL), "sal.osl",
"no FileStatus LinkTargetURL determined");
return isValid(osl_FileStatus_Mask_LinkTargetURL)
? rtl::OUString(_aStatus.ustrLinkTargetURL) : rtl::OUString();
}
friend class DirectoryItem;
};
/** The file class object provides access to file contents and attributes.
@see Directory
@see DirectoryItem
*/
class File: public FileBase
{
oslFileHandle _pData;
::rtl::OUString _aPath;
/** Copy constructor.
*/
File( File& ) SAL_DELETED_FUNCTION;
/** Assignment operator.
*/
File& operator = ( File& ) SAL_DELETED_FUNCTION;
public:
/** Constructor.
@param[in] ustrFileURL
The full qualified URL of the file. Relative paths are not allowed.
*/
File( const ::rtl::OUString& ustrFileURL ): _pData( NULL ), _aPath( ustrFileURL ) {}
/** Destructor
*/
~File()
{
close();
}
/** Obtain the URL.
@return
the URL with which this File instance was created.
@since LibreOffice 4.1
*/
rtl::OUString getURL() const { return _aPath; }
/** Open a regular file.
Open a file. Only regular files can be openend.
@param[in] uFlags
Specifies the open mode.
@retval E_None on success
@retval E_NOMEM not enough memory for allocating structures
@retval E_INVAL the format of the parameters was not valid
@retval E_NAMETOOLONG pathname was too long
@retval E_NOENT no such file or directory
@retval E_ACCES permission denied
@retval E_AGAIN a write lock could not be established
@retval E_NOTDIR not a directory
@retval E_NXIO no such device or address
@retval E_NODEV no such device
@retval E_ROFS read-only file system
@retval E_TXTBSY text file busy
@retval E_FAULT bad address
@retval E_LOOP too many symbolic links encountered
@retval E_NOSPC no space left on device
@retval E_ISDIR is a directory
@retval E_MFILE too many open files used by the process
@retval E_NFILE too many open files in the system
@retval E_DQUOT quota exceeded
@retval E_EXIST file exists
@retval E_INTR function call was interrupted
@retval E_IO on I/O errors
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@retval E_EOVERFLOW value too large for defined data type
@see close()
@see setPos()
@see getPos()
@see read()
@see write()
@see getSize()
@see setSize()
*/
RC open( sal_uInt32 uFlags )
{
return static_cast< RC >( osl_openFile( _aPath.pData, &_pData, uFlags ) );
}
/** Close an open file.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_BADF Bad file
@retval E_INTR function call was interrupted
@retval E_NOLINK link has been severed
@retval E_NOSPC no space left on device
@retval E_IO on I/O errors
@see open()
*/
RC close()
{
oslFileError Error = osl_File_E_BADF;
if( _pData )
{
Error=osl_closeFile( _pData );
_pData = NULL;
}
return static_cast< RC >( Error );
}
/** Set the internal position pointer of an open file.
@param[in] uHow
Distance to move the internal position pointer (from uPos).
@param[in] uPos
Absolute position from the beginning of the file.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
@see open()
@see getPos()
*/
RC setPos( sal_uInt32 uHow, sal_Int64 uPos ) SAL_WARN_UNUSED_RESULT
{
return static_cast< RC >( osl_setFilePos( _pData, uHow, uPos ) );
}
/** Retrieve the current position of the internal pointer of an open file.
@param[out] uPos
On success receives the current position of the file pointer.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
@see open()
@see setPos()
@see read()
@see write()
*/
RC getPos( sal_uInt64& uPos )
{
return static_cast< RC >( osl_getFilePos( _pData, &uPos ) );
}
/** Test if the end of a file is reached.
@param[out] pIsEOF
Points to a variable that receives the end-of-file status.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_INTR function call was interrupted
@retval E_IO on I/O errors
@retval E_ISDIR is a directory
@retval E_BADF bad file
@retval E_FAULT bad address
@retval E_AGAIN operation would block
@retval E_NOLINK link has been severed
@see open()
@see read()
@see readLine()
@see setPos()
*/
RC isEndOfFile( sal_Bool *pIsEOF )
{
return static_cast< RC >( osl_isEndOfFile( _pData, pIsEOF ) );
}
/** Set the file size of an open file.
Sets the file size of an open file. The file can be truncated or enlarged by the function.
The position of the file pointer is not affeced by this function.
@param[in] uSize
New size in bytes.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
@see open()
@see setPos()
@see getStatus()
*/
RC setSize( sal_uInt64 uSize )
{
return static_cast< RC >( osl_setFileSize( _pData, uSize ) );
}
/** Get the file size of an open file.
Gets the file size of an open file.
The position of the file pointer is not affeced by this function.
@param[out] rSize
Current size in bytes.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
@see open()
@see setPos()
@see getSize()
@see setSize()
@see getStatus()
*/
RC getSize( sal_uInt64 &rSize )
{
return static_cast< RC >( osl_getFileSize( _pData, &rSize ) );
}
/** Read a number of bytes from a file.
Reads a number of bytes from a file. The internal file pointer is
increased by the number of bytes read.
@param[out] pBuffer
Points to a buffer which receives data. The buffer must be large enough
to hold uBytesRequested bytes.
@param[in] uBytesRequested
Number of bytes which should be retrieved.
@param[out] rBytesRead
On success the number of bytes which have actually been retrieved.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_INTR function call was interrupted
@retval E_IO on I/O errors
@retval E_ISDIR is a directory
@retval E_BADF bad file
@retval E_FAULT bad address
@retval E_AGAIN operation would block
@retval E_NOLINK link has been severed
@see open()
@see write()
@see readLine()
@see setPos()
*/
RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
{
return static_cast< RC >( osl_readFile( _pData, pBuffer, uBytesRequested, &rBytesRead ) );
}
/** Write a number of bytes to a file.
Writes a number of bytes to a file.
The internal file pointer is increased by the number of bytes read.
@param[in] pBuffer
Points to a buffer which contains the data.
@param[in] uBytesToWrite
Number of bytes which should be written.
@param[out] rBytesWritten
On success the number of bytes which have actually been written.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_FBIG file too large
@retval E_DQUOT quota exceeded
@retval E_AGAIN operation would block
@retval E_BADF bad file
@retval E_FAULT bad address
@retval E_INTR function call was interrupted
@retval E_IO on I/O errosr
@retval E_NOLCK no record locks available
@retval E_NOLINK link has been severed
@retval E_NOSPC no space left on device
@retval E_NXIO no such device or address
@see open()
@see read()
@see setPos()
*/
RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
{
return static_cast< RC >( osl_writeFile( _pData, pBuffer, uBytesToWrite, &rBytesWritten ) );
}
/** Read a line from a file.
Reads a line from a file. The new line delimiter is NOT returned!
@param[in,out] aSeq
A reference to a ::rtl::ByteSequence that will hold the line read on success.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_INTR function call was interrupted
@retval E_IO on I/O errors
@retval E_ISDIR is a directory
@retval E_BADF bad file
@retval E_FAULT bad address
@retval E_AGAIN operation would block
@retval E_NOLINK link has been severed
@see open()
@see read()
@see write()
@see setPos()
*/
RC readLine( ::rtl::ByteSequence& aSeq )
{
return static_cast< RC >( osl_readLine( _pData, reinterpret_cast<sal_Sequence**>(&aSeq) ) );
}
/** Synchronize the memory representation of a file with that on the physical medium.
The function ensures that all modified data and attributes of the file associated with
the given file handle have been written to the physical medium.
In case the hard disk has a write cache enabled, the data may not really be on
permanent storage when osl_syncFile returns.
@retval E_None On success
@retval E_INVAL The value of the input parameter is invalid
@retval E_BADF The file is not open for writing
@retval E_IO An I/O error occurred
@retval E_NOSPC There is no enough space on the target device
@retval E_ROFS The file is located on a read only file system
@retval E_TIMEDOUT A remote connection timed out. This may happen when a file is on a remote location
@see osl_syncFile()
@see open()
@see write()
*/
RC sync() const
{
OSL_PRECOND(_pData, "File::sync(): File not open");
return static_cast< RC >(osl_syncFile(_pData));
}
/** Copy a file to a new destination.
Copies a file to a new destination. Copies only files not directories.
No assumptions should be made about preserving attributes or file time.
@param[in] ustrSourceFileURL
Full qualified URL of the source file.
@param[in] ustrDestFileURL
Full qualified URL of the destination file. A directory is NOT a valid destination file!
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_PERM operation not permitted
@retval E_NAMETOOLONG file name too long
@retval E_NOENT no such file or directory
@retval E_ISDIR is a directory
@retval E_ROFS read-only file system
@see move()
@see remove()
*/
static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
{
return static_cast< RC >( osl_copyFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
}
/** Move a file or directory to a new destination or renames it.
Moves a file or directory to a new destination or renames it.
File time and attributes are preserved.
@param[in] ustrSourceFileURL
Full qualified URL of the source file.
@param[in] ustrDestFileURL
Full qualified URL of the destination file. An existing directory is NOT a valid destination !
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_PERM operation not permitted
@retval E_NAMETOOLONG file name too long
@retval E_NOENT no such file or directory
@retval E_ROFS read-only file system
@see copy()
*/
static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
{
return static_cast< RC >( osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
}
/** Remove a regular file.
@param[in] ustrFileURL
Full qualified URL of the file to remove.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_PERM operation not permitted
@retval E_NAMETOOLONG file name too long
@retval E_NOENT no such file or directory
@retval E_ISDIR is a directory
@retval E_ROFS read-only file system
@retval E_FAULT bad address
@retval E_LOOP too many symbolic links encountered
@retval E_IO on I/O errors
@retval E_BUSY device or resource busy
@retval E_INTR function call was interrupted
@retval E_LOOP too many symbolic links encountered
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@retval E_TXTBSY text file busy
@see open()
*/
static RC remove( const ::rtl::OUString& ustrFileURL )
{
return static_cast< RC >( osl_removeFile( ustrFileURL.pData ) );
}
/** Set file attributes.
@param[in] ustrFileURL
The full qualified file URL.
@param[in] uAttributes
Attributes of the file to be set.
@return
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@see FileStatus
*/
static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
{
return static_cast< RC >( osl_setFileAttributes( ustrFileURL.pData, uAttributes ) );
}
/** Set the file time.
@param[in] ustrFileURL
The full qualified URL of the file.
@param[in] rCreationTime
Creation time of the given file.
@param[in] rLastAccessTime
Time of the last access of the given file.
@param[in] rLastWriteTime
Time of the last modifying of the given file.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOENT no such file or directory not found
@see FileStatus
*/
static RC setTime(
const ::rtl::OUString& ustrFileURL,
const TimeValue& rCreationTime,
const TimeValue& rLastAccessTime,
const TimeValue& rLastWriteTime )
{
return static_cast< RC >( osl_setFileTime(
ustrFileURL.pData,
&rCreationTime,
&rLastAccessTime,
&rLastWriteTime ) );
}
friend class DirectoryItem;
};
/** The directory item class object provides access to file status information.
@see FileStatus
*/
class DirectoryItem: public FileBase
{
oslDirectoryItem _pData;
public:
/** Constructor.
*/
DirectoryItem(): _pData( NULL )
{
}
/** Copy constructor.
*/
DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
{
if( _pData )
osl_acquireDirectoryItem( _pData );
}
/** Destructor.
*/
~DirectoryItem()
{
if( _pData )
osl_releaseDirectoryItem( _pData );
}
/** Assignment operator.
*/
DirectoryItem& operator=(const DirectoryItem& rItem )
{
if (&rItem != this)
{
if( _pData )
osl_releaseDirectoryItem( _pData );
_pData = rItem._pData;
if( _pData )
osl_acquireDirectoryItem( _pData );
}
return *this;
}
/** Check for validity of this instance.
@return
true if object is valid directory item else false.
*/
bool is()
{
return _pData != NULL;
}
/** Retrieve a single directory item.
Retrieves a single directory item. The returned handle has an initial refcount of 1.
Due to performance issues it is not recommended to use this function while
enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead.
@param[in] ustrFileURL
An absolute file URL.
@param[out] rItem
On success it receives a handle which can be used for subsequent calls to osl_getFileStatus().
The handle has to be released by a call to osl_releaseDirectoryItem().
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_MFILE too many open files used by the process
@retval E_NFILE too many open files in the system
@retval E_NOENT no such file or directory
@retval E_LOOP too many symbolic links encountered
@retval E_NAMETOOLONG the file name is too long
@retval E_NOTDIR a component of the path prefix of path is not a directory
@retval E_IO on I/O errors
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@retval E_FAULT bad address
@retval E_INTR the function call was interrupted
@see FileStatus
@see Directory::getNextItem()
*/
static RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
{
if( rItem._pData)
{
osl_releaseDirectoryItem( rItem._pData );
rItem._pData = NULL;
}
return static_cast< RC >( osl_getDirectoryItem( ustrFileURL.pData, &rItem._pData ) );
}
/** Retrieve information about a single file or directory.
@param[in,out] rStatus
Reference to a class which receives the information of the file or directory
represented by this directory item.
@retval E_None on success
@retval E_NOMEM not enough memory for allocating structures
@retval E_INVAL the format of the parameters was not valid
@retval E_LOOP too many symbolic links encountered
@retval E_ACCES permission denied
@retval E_NOENT no such file or directory
@retval E_NAMETOOLONG file name too long
@retval E_BADF invalid oslDirectoryItem parameter
@retval E_FAULT bad address
@retval E_OVERFLOW value too large for defined data type
@retval E_INTR function call was interrupted
@retval E_NOLINK link has been severed
@retval E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it
@retval E_MFILE too many open files used by the process
@retval E_NFILE too many open files in the system
@retval E_NOSPC no space left on device
@retval E_NXIO no such device or address
@retval E_IO on I/O errors
@retval E_NOSYS function not implemented
@see get()
@see Directory::getNextItem()
@see FileStatus
*/
RC getFileStatus( FileStatus& rStatus )
{
return static_cast< RC >( osl_getFileStatus( _pData, &rStatus._aStatus, rStatus._nMask ) );
}
/** Determine if a directory item point the same underlying file
The comparison is done first by URL, and then by resolving links to
find the target, and finally by comparing inodes on unix.
@param[in] pOther
A directory handle to compare with the underlying object's item
@retval true if the items point to an identical resource<br>
@retval false if the items point to a different resource, or a fatal error occurred<br>
@see osl_getDirectoryItem()
@since LibreOffice 3.6
*/
bool isIdenticalTo( const DirectoryItem &pOther )
{
return osl_identicalDirectoryItem( _pData, pOther._pData );
}
friend class Directory;
};
/** Base class for observers of directory creation notifications.
Clients which uses the method createDirectoryPath of the class
Directory may want to be informed about the directories that
have been created. This may be accomplished by deriving from
this base class and overwriting the virtual function
DirectoryCreated.
@see Directory::createPath
*/
class DirectoryCreationObserver
{
public:
virtual ~DirectoryCreationObserver() {}
/** This method will be called when a new directory has been
created and needs to be overwritten by derived classes.
You must not delete the directory that was just created
otherwise you will run into an endless loop.
@param aDirectoryUrl
[in]The absolute file URL of the directory that was just created by
::osl::Directory::createPath.
*/
virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) = 0;
};
// This just an internal helper function for
// private use.
extern "C" inline void SAL_CALL onDirectoryCreated(void* pData, rtl_uString* aDirectoryUrl)
{
static_cast<DirectoryCreationObserver*>(pData)->DirectoryCreated(aDirectoryUrl);
}
/** The directory class object provides a enumeration of DirectoryItems.
@see DirectoryItem
@see File
*/
class Directory: public FileBase
{
oslDirectory _pData;
::rtl::OUString _aPath;
/** Copy constructor.
*/
Directory( Directory& ) SAL_DELETED_FUNCTION;
/** Assignment operator.
*/
Directory& operator = ( Directory& ) SAL_DELETED_FUNCTION;
public:
/** Constructor.
@param[in] strPath
The full qualified URL of the directory.
Relative URLs are not allowed.
*/
Directory( const ::rtl::OUString& strPath ): _pData( NULL ), _aPath( strPath )
{
}
/** Destructor.
*/
~Directory()
{
close();
}
/** Obtain the URL.
@return
the URL with which this Directory instance was created.
@since LibreOffice 4.1
*/
rtl::OUString getURL() const { return _aPath; }
/** Open a directory for enumerating its contents.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOENT the specified path doesn't exist
@retval E_NOTDIR the specified path is not an directory
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_MFILE too many open files used by the process
@retval E_NFILE too many open files in the system
@retval E_NAMETOOLONG File name too long
@retval E_LOOP Too many symbolic links encountered
@see getNextItem()
@see close()
*/
RC open()
{
return static_cast< RC >( osl_openDirectory( _aPath.pData, &_pData ) );
}
/** Query if directory is open.
Query if directory is open and so item enumeration is valid.
@retval true if the directory is open else false.
@see open()
@see close()
*/
bool isOpen() { return _pData != NULL; }
/** Close a directory.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_BADF invalid oslDirectory parameter
@retval E_INTR the function call was interrupted
@see open()
*/
RC close()
{
oslFileError Error = osl_File_E_BADF;
if( _pData )
{
Error=osl_closeDirectory( _pData );
_pData = NULL;
}
return static_cast< RC >( Error );
}
/** Resets the directory item enumeration to the beginning.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOENT the specified path doesn't exist
@retval E_NOTDIR the specified path is not an directory
@retval E_NOMEM not enough memory for allocating structures
@retval E_ACCES permission denied
@retval E_MFILE too many open files used by the process
@retval E_NFILE too many open files in the system
@retval E_NAMETOOLONG File name too long
@retval E_LOOP Too many symbolic links encountered
@see open()
*/
RC reset()
{
close();
return open();
}
/** Retrieve the next item of a previously opened directory.
Retrieves the next item of a previously opened directory.
@param[out] rItem
On success a valid DirectoryItem.
@param[in] nHint
With this parameter the caller can tell the implementation that (s)he
is going to call this function uHint times afterwards. This enables the implementation to
get the information for more than one file and cache it until the next calls.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_NOENT no more entries in this directory
@retval E_BADF invalid oslDirectory parameter
@retval E_OVERFLOW the value too large for defined data type
@see DirectoryItem
*/
RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
{
if( rItem._pData )
{
osl_releaseDirectoryItem( rItem._pData );
rItem._pData = NULL;
}
return static_cast<RC>(osl_getNextDirectoryItem( _pData, &rItem._pData, nHint ));
}
/** Retrieve information about a volume.
Retrieves information about a volume. A volume can either be a mount point, a network
resource or a drive depending on Operating System and File System.
@param[in] ustrDirectoryURL
Full qualified URL of the volume
@param[out] rInfo
On success it receives information about the volume.
@retval E_None on success
@retval E_NOMEM not enough memory for allocating structures
@retval E_INVAL the format of the parameters was not valid
@retval E_NOTDIR not a directory
@retval E_NAMETOOLONG file name too long
@retval E_NOENT no such file or directory
@retval E_ACCES permission denied
@retval E_LOOP too many symbolic links encountered
@retval E_FAULT Bad address
@retval E_IO on I/O errors
@retval E_NOSYS function not implemented
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@retval E_INTR function call was interrupted
@see FileStatus
@see VolumeInfo
*/
static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
{
return static_cast< RC >( osl_getVolumeInformation( ustrDirectoryURL.pData, &rInfo._aInfo, rInfo._nMask ) );
}
/** Create a directory.
@param[in] ustrDirectoryURL
Full qualified URL of the directory to create.
@param[in] flags
Optional flags, see osl_createDirectoryWithFlags for details. This
defaulted parameter is new since LibreOffice 4.3.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_EXIST file exists
@retval E_ACCES permission denied
@retval E_NAMETOOLONG file name too long
@retval E_NOENT no such file or directory
@retval E_NOTDIR not a directory
@retval E_ROFS read-only file system
@retval E_NOSPC no space left on device
@retval E_DQUOT quota exceeded
@retval E_LOOP too many symbolic links encountered
@retval E_FAULT bad address
@retval E_IO on I/O errors
@retval E_MLINK too many links
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@see remove()
*/
static RC create(
const ::rtl::OUString& ustrDirectoryURL,
sal_uInt32 flags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write )
{
return static_cast< RC >(
osl_createDirectoryWithFlags( ustrDirectoryURL.pData, flags ) );
}
/** Remove an empty directory.
@param[in] ustrDirectoryURL
Full qualified URL of the directory.
@retval E_None on success
@retval E_INVAL the format of the parameters was not valid
@retval E_NOMEM not enough memory for allocating structures
@retval E_PERM operation not permitted
@retval E_ACCES permission denied
@retval E_NOENT no such file or directory
@retval E_NOTDIR not a directory
@retval E_NOTEMPTY directory not empty
@retval E_FAULT bad address
@retval E_NAMETOOLONG file name too long
@retval E_BUSY device or resource busy
@retval E_ROFS read-only file system
@retval E_LOOP too many symbolic links encountered
@retval E_BUSY device or resource busy
@retval E_EXIST file exists
@retval E_IO on I/O errors
@retval E_MULTIHOP multihop attempted
@retval E_NOLINK link has been severed
@see create()
*/
static RC remove( const ::rtl::OUString& ustrDirectoryURL )
{
return static_cast< RC >( osl_removeDirectory( ustrDirectoryURL.pData ) );
}
/** Create a directory path.
The osl_createDirectoryPath function creates a specified directory path.
All nonexisting sub directories will be created.
@attention You cannot rely on getting the error code E_EXIST for existing
directories. Programming against this error code is in general a strong
indication of a wrong usage of osl_createDirectoryPath.
@param aDirectoryUrl
[in] The absolute file URL of the directory path to create.
A relative file URL will not be accepted.
@param aDirectoryCreationObserver
[in] Pointer to an instance of type DirectoryCreationObserver that will
be informed about the creation of a directory. The value of this
parameter may be NULL, in this case notifications will not be sent.
@retval E_None On success
@retval E_INVAL The format of the parameters was not valid
@retval E_ACCES Permission denied
@retval E_EXIST The final node of the specified directory path already exist
@retval E_NAMETOOLONG The name of the specified directory path exceeds the maximum allowed length
@retval E_NOTDIR A component of the specified directory path already exist as file in any part of the directory path
@retval E_ROFS Read-only file system
@retval E_NOSPC No space left on device
@retval E_DQUOT Quota exceeded
@retval E_FAULT Bad address
@retval E_IO I/O error
@retval E_LOOP Too many symbolic links encountered
@retval E_NOLINK Link has been severed
@retval E_invalidError An unknown error occurred
@see DirectoryCreationObserver
@see create
*/
static RC createPath(
const ::rtl::OUString& aDirectoryUrl,
DirectoryCreationObserver* aDirectoryCreationObserver = NULL)
{
return static_cast< RC >(osl_createDirectoryPath(
aDirectoryUrl.pData,
aDirectoryCreationObserver ? onDirectoryCreated : NULL,
aDirectoryCreationObserver));
}
};
} /* namespace osl */
#endif // INCLUDED_OSL_FILE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|