ObjFW
Loading...
Searching...
No Matches
OFFileManager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21#import "OFDictionary.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
27#ifdef OF_HAVE_FILES
28# if (defined(OF_HAVE_CHMOD) && !defined(OF_AMIGAOS)) || defined(DOXYGEN)
29# define OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
30# endif
31# if (defined(OF_HAVE_CHOWN) && !defined(OF_AMIGAOS)) || defined(DOXYGEN)
32# define OF_FILE_MANAGER_SUPPORTS_OWNER
33# endif
34# if (defined(OF_HAVE_LINK) && !defined(OF_AMIGAOS) && !defined(OF_HAIKU)) || \
35 defined(OF_WINDOWS) || defined(DOXYGEN)
36# define OF_FILE_MANAGER_SUPPORTS_LINKS
37# endif
38# if (defined(OF_HAVE_SYMLINK) && !defined(OF_AMIGAOS)) || \
39 defined(OF_WINDOWS) || defined(DOXYGEN)
40# define OF_FILE_MANAGER_SUPPORTS_SYMLINKS
41# endif
42# if defined(OF_LINUX) || defined(OF_MACOS) || defined(OF_FREEBSD) || \
43 defined(OF_NETBSD) || defined(OF_HAIKU) || defined(DOXYGEN)
44# define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
45# endif
46#endif
47
48@class OFArray OF_GENERIC(ObjectType);
49@class OFConstantString;
50@class OFDate;
51@class OFIRI;
52@class OFString;
53
76
94
100
105typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id)
107
108#ifdef __cplusplus
109extern "C" {
110#endif
117extern const OFFileAttributeKey OFFileSize;
118
127extern const OFFileAttributeKey OFFileType;
128
136
144
152
160
168
176
184
192
200
208
217
222
227
232
237
242
247
252
261#ifdef __cplusplus
262}
263#endif
264
271#ifndef OF_FILE_MANAGER_M
272OF_SUBCLASSING_RESTRICTED
273#endif
275#ifdef OF_HAVE_CLASS_PROPERTIES
276@property (class, readonly, nonatomic) OFFileManager *defaultManager;
277#endif
278
279#ifdef OF_HAVE_FILES
285@property (readonly, nonatomic) OFString *currentDirectoryPath;
286
292@property (readonly, nonatomic) OFIRI *currentDirectoryIRI;
293#endif
294
299
300#ifdef OF_HAVE_FILES
310- (OFFileAttributes)attributesOfItemAtPath: (OFString *)path;
311#endif
312
324- (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI;
325
326#ifdef OF_HAVE_FILES
340- (void)setAttributes: (OFFileAttributes)attributes
341 ofItemAtPath: (OFString *)path;
342#endif
343
359- (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI;
360
361#ifdef OF_HAVE_FILES
368- (bool)fileExistsAtPath: (OFString *)path;
369#endif
370
379- (bool)fileExistsAtIRI: (OFIRI *)IRI;
380
381#ifdef OF_HAVE_FILES
388- (bool)directoryExistsAtPath: (OFString *)path;
389#endif
390
399- (bool)directoryExistsAtIRI: (OFIRI *)IRI;
400
401#ifdef OF_HAVE_FILES
408- (void)createDirectoryAtPath: (OFString *)path;
409
418- (void)createDirectoryAtPath: (OFString *)path
419 createParents: (bool)createParents;
420#endif
421
430- (void)createDirectoryAtIRI: (OFIRI *)IRI;
431
442- (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents;
443
444#ifdef OF_HAVE_FILES
455- (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path;
456#endif
457
471- (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI;
472
473#ifdef OF_HAVE_FILES
483- (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path;
484
492- (void)changeCurrentDirectoryPath: (OFString *)path;
493
501- (void)changeCurrentDirectoryIRI: (OFIRI *)IRI;
502
519- (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination;
520#endif
521
540- (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
541
542#ifdef OF_HAVE_FILES
564- (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination;
565#endif
566
590- (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
591
592#ifdef OF_HAVE_FILES
601- (void)removeItemAtPath: (OFString *)path;
602#endif
603
614- (void)removeItemAtIRI: (OFIRI *)IRI;
615
616#ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
631- (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination;
632#endif
633
650- (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
651
652#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
670- (void)createSymbolicLinkAtPath: (OFString *)path
671 withDestinationPath: (OFString *)target;
672#endif
673
691- (void)createSymbolicLinkAtIRI: (OFIRI *)IRI
692 withDestinationPath: (OFString *)target;
693
694#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
710- (OFData *)extendedAttributeDataForName: (OFString *)name
711 ofItemAtPath: (OFString *)path;
712
732- (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
733 andType: (id _Nullable *_Nullable)type
734 forName: (OFString *)name
735 ofItemAtPath: (OFString *)path;
736#endif
737
755- (OFData *)extendedAttributeDataForName: (OFString *)name
756 ofItemAtIRI: (OFIRI *)IRI;
757
779- (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
780 andType: (id _Nullable *_Nullable)type
781 forName: (OFString *)name
782 ofItemAtIRI: (OFIRI *)IRI;
783
784#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
799- (void)setExtendedAttributeData: (OFData *)data
800 forName: (OFString *)name
801 ofItemAtPath: (OFString *)path;
802
822- (void)setExtendedAttributeData: (OFData *)data
823 andType: (nullable id)type
824 forName: (OFString *)name
825 ofItemAtPath: (OFString *)path;
826#endif
827
844- (void)setExtendedAttributeData: (OFData *)data
845 forName: (OFString *)name
846 ofItemAtIRI: (OFIRI *)IRI;
847
869- (void)setExtendedAttributeData: (OFData *)data
870 andType: (nullable id)type
871 forName: (OFString *)name
872 ofItemAtIRI: (OFIRI *)IRI;
873
874#ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
888- (void)removeExtendedAttributeForName: (OFString *)name
889 ofItemAtPath: (OFString *)path;
890#endif
891
907- (void)removeExtendedAttributeForName: (OFString *)name
908 ofItemAtIRI: (OFIRI *)IRI;
909@end
910
911@interface OFDictionary (FileAttributes)
917@property (readonly, nonatomic) unsigned long long fileSize;
918
924@property (readonly, nonatomic) OFFileAttributeType fileType;
925
931@property (readonly, nonatomic) unsigned long filePOSIXPermissions;
932
938@property (readonly, nonatomic) unsigned long fileOwnerAccountID;
939
945@property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID;
946
952@property (readonly, nonatomic) OFString *fileOwnerAccountName;
953
959@property (readonly, nonatomic) OFString *fileGroupOwnerAccountName;
960
966@property (readonly, nonatomic) OFDate *fileLastAccessDate;
967
973@property (readonly, nonatomic) OFDate *fileModificationDate;
974
980@property (readonly, nonatomic) OFDate *fileStatusChangeDate;
981
987@property (readonly, nonatomic) OFDate *fileCreationDate;
988
994@property (readonly, nonatomic) OFString *fileSymbolicLinkDestination;
995
1001@property (readonly, nonatomic)
1003@end
1004
1005OF_ASSUME_NONNULL_END
const OFFileAttributeType OFFileTypeFIFO
A FIFO.
const OFFileAttributeKey OFFileCreationDate
The creation date of the file as an OFDate.
const OFFileAttributeKey OFFileOwnerAccountName
The account name of the owner of the file as an OFString.
const OFFileAttributeKey OFFileExtendedAttributesNames
The names of the extended attributes as an OFArray of OFString.
const OFFileAttributeKey OFFilePOSIXPermissions
The POSIX permissions of the file as an OFNumber.
OFConstantString * OFFileAttributeType
The type of a file.
Definition OFFileManager.h:93
const OFFileAttributeType OFFileTypeBlockSpecial
A block special file.
const OFFileAttributeKey OFFileGroupOwnerAccountID
The account ID of the group owner of the file as an OFNumber.
const OFFileAttributeKey OFFileGroupOwnerAccountName
The account name of the group owner of the file as an OFString.
const OFFileAttributeType OFFileTypeSocket
A socket.
const OFFileAttributeKey OFFileStatusChangeDate
The last status change date of the file as an OFDate.
OFConstantString * OFFileAttributeKey
A key for a file attribute in the file attributes dictionary.
Definition OFFileManager.h:75
OFMutableDictionary * OFMutableFileAttributes
A mutable dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition OFFileManager.h:106
const OFFileAttributeType OFFileTypeRegular
A regular file.
const OFFileAttributeKey OFFileSymbolicLinkDestination
The destination of a symbolic link as an OFString.
const OFFileAttributeKey OFFileType
The type of the file.
const OFFileAttributeKey OFFileModificationDate
The last modification date of the file as an OFDate.
const OFFileAttributeType OFFileTypeCharacterSpecial
A character special file.
const OFFileAttributeKey OFFileSize
The size of the file as an OFNumber.
const OFFileAttributeType OFFileTypeSymbolicLink
A symbolic link.
const OFFileAttributeKey OFFileOwnerAccountID
The account ID of the owner of the file as an OFNumber.
const OFFileAttributeType OFFileTypeUnknown
An unknown file type.
OFDictionary * OFFileAttributes
A dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition OFFileManager.h:99
const OFFileAttributeKey OFFileLastAccessDate
The last access date of the file as an OFDate.
const OFFileAttributeType OFFileTypeDirectory
A directory.
An abstract class for storing objects in an array.
Definition OFArray.h:109
A class for storing constant strings using the @"" literal.
Definition OFConstantString.h:42
A class for storing arbitrary data in an array.
Definition OFData.h:46
A class for storing, accessing and comparing dates.
Definition OFDate.h:34
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
OFArray * fileExtendedAttributesNames
Definition OFFileManager.h:1002
A class which provides management for files, e.g. reading contents of directories,...
Definition OFFileManager.h:275
OFFileManager * defaultManager()
Returns the default file manager.
Definition OFFileManager.m:136
OFIRI * currentDirectoryIRI
The IRI of the current working directory.
Definition OFFileManager.h:292
OFString * currentDirectoryPath
The path of the current working directory.
Definition OFFileManager.h:285
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition OFIRI.h:41
An abstract class for storing and changing objects in a dictionary.
Definition OFMutableDictionary.h:48
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A class for handling strings.
Definition OFString.h:139