ObjFW
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 
23 OF_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(OF_SOLARIS) || \
44  defined(DOXYGEN)
45 # define OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
46 # endif
47 #endif
48 
49 @class OFArray OF_GENERIC(ObjectType);
50 @class OFConstantString;
51 @class OFDate;
52 @class OFIRI;
53 @class OFString;
54 
77 
95 
101 
106 typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id)
108 
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112 
118 extern const OFFileAttributeKey OFFileSize;
119 
128 extern const OFFileAttributeKey OFFileType;
129 
137 
145 
153 
161 
169 
177 
185 
193 
201 
209 
218 
223 
228 
233 
238 
243 
248 
253 
262 #ifdef __cplusplus
263 }
264 #endif
265 
272 #ifndef OF_FILE_MANAGER_M
273 OF_SUBCLASSING_RESTRICTED
274 #endif
276 #ifdef OF_HAVE_CLASS_PROPERTIES
277 @property (class, readonly, nonatomic) OFFileManager *defaultManager;
278 #endif
279 
280 #ifdef OF_HAVE_FILES
281 
286 @property (readonly, nonatomic) OFString *currentDirectoryPath;
287 
293 @property (readonly, nonatomic) OFIRI *currentDirectoryIRI;
294 #endif
295 
300 
301 #ifdef OF_HAVE_FILES
302 
311 - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path;
312 #endif
313 
325 - (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI;
326 
327 #ifdef OF_HAVE_FILES
328 
341 - (void)setAttributes: (OFFileAttributes)attributes
342  ofItemAtPath: (OFString *)path;
343 #endif
344 
360 - (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI;
361 
362 #ifdef OF_HAVE_FILES
363 
369 - (bool)fileExistsAtPath: (OFString *)path;
370 #endif
371 
380 - (bool)fileExistsAtIRI: (OFIRI *)IRI;
381 
382 #ifdef OF_HAVE_FILES
383 
389 - (bool)directoryExistsAtPath: (OFString *)path;
390 #endif
391 
400 - (bool)directoryExistsAtIRI: (OFIRI *)IRI;
401 
402 #ifdef OF_HAVE_FILES
403 
409 - (void)createDirectoryAtPath: (OFString *)path;
410 
419 - (void)createDirectoryAtPath: (OFString *)path
420  createParents: (bool)createParents;
421 #endif
422 
431 - (void)createDirectoryAtIRI: (OFIRI *)IRI;
432 
443 - (void)createDirectoryAtIRI: (OFIRI *)IRI createParents: (bool)createParents;
444 
445 #ifdef OF_HAVE_FILES
446 
456 - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path;
457 #endif
458 
472 - (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI;
473 
474 #ifdef OF_HAVE_FILES
475 
484 - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path;
485 
493 - (void)changeCurrentDirectoryPath: (OFString *)path;
494 
502 - (void)changeCurrentDirectoryIRI: (OFIRI *)IRI;
503 
520 - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination;
521 #endif
522 
541 - (void)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
542 
543 #ifdef OF_HAVE_FILES
544 
565 - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination;
566 #endif
567 
591 - (void)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
592 
593 #ifdef OF_HAVE_FILES
594 
602 - (void)removeItemAtPath: (OFString *)path;
603 #endif
604 
615 - (void)removeItemAtIRI: (OFIRI *)IRI;
616 
617 #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
618 
632 - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination;
633 #endif
634 
651 - (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination;
652 
653 #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
654 
671 - (void)createSymbolicLinkAtPath: (OFString *)path
672  withDestinationPath: (OFString *)target;
673 #endif
674 
692 - (void)createSymbolicLinkAtIRI: (OFIRI *)IRI
693  withDestinationPath: (OFString *)target;
694 
695 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
696 
711 - (OFData *)extendedAttributeDataForName: (OFString *)name
712  ofItemAtPath: (OFString *)path;
713 
733 - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
734  andType: (id _Nullable *_Nullable)type
735  forName: (OFString *)name
736  ofItemAtPath: (OFString *)path;
737 #endif
738 
756 - (OFData *)extendedAttributeDataForName: (OFString *)name
757  ofItemAtIRI: (OFIRI *)IRI;
758 
780 - (void)getExtendedAttributeData: (OFData *_Nonnull *_Nonnull)data
781  andType: (id _Nullable *_Nullable)type
782  forName: (OFString *)name
783  ofItemAtIRI: (OFIRI *)IRI;
784 
785 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
786 
800 - (void)setExtendedAttributeData: (OFData *)data
801  forName: (OFString *)name
802  ofItemAtPath: (OFString *)path;
803 
823 - (void)setExtendedAttributeData: (OFData *)data
824  andType: (nullable id)type
825  forName: (OFString *)name
826  ofItemAtPath: (OFString *)path;
827 #endif
828 
845 - (void)setExtendedAttributeData: (OFData *)data
846  forName: (OFString *)name
847  ofItemAtIRI: (OFIRI *)IRI;
848 
870 - (void)setExtendedAttributeData: (OFData *)data
871  andType: (nullable id)type
872  forName: (OFString *)name
873  ofItemAtIRI: (OFIRI *)IRI;
874 
875 #ifdef OF_FILE_MANAGER_SUPPORTS_EXTENDED_ATTRIBUTES
876 
889 - (void)removeExtendedAttributeForName: (OFString *)name
890  ofItemAtPath: (OFString *)path;
891 #endif
892 
908 - (void)removeExtendedAttributeForName: (OFString *)name
909  ofItemAtIRI: (OFIRI *)IRI;
910 @end
911 
912 @interface OFDictionary (FileAttributes)
918 @property (readonly, nonatomic) unsigned long long fileSize;
919 
925 @property (readonly, nonatomic) OFFileAttributeType fileType;
926 
932 @property (readonly, nonatomic) unsigned long filePOSIXPermissions;
933 
939 @property (readonly, nonatomic) unsigned long fileOwnerAccountID;
940 
946 @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID;
947 
953 @property (readonly, nonatomic) OFString *fileOwnerAccountName;
954 
960 @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName;
961 
967 @property (readonly, nonatomic) OFDate *fileLastAccessDate;
968 
974 @property (readonly, nonatomic) OFDate *fileModificationDate;
975 
981 @property (readonly, nonatomic) OFDate *fileStatusChangeDate;
982 
988 @property (readonly, nonatomic) OFDate *fileCreationDate;
989 
995 @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination;
996 
1002 @property (readonly, nonatomic)
1003  OFArray OF_GENERIC(OFString *) *fileExtendedAttributesNames;
1004 @end
1005 
1006 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
const OFFileAttributeKey OFFileModificationDate
The last modification date of the file as an OFDate.
const OFFileAttributeType OFFileTypeSocket
A socket.
OFConstantString * OFFileAttributeKey
A key for a file attribute in the file attributes dictionary.
Definition: OFFileManager.h:53
const OFFileAttributeKey OFFileLastAccessDate
The last access date of the file as an OFDate.
const OFFileAttributeType OFFileTypeSymbolicLink
A symbolic link.
const OFFileAttributeType OFFileTypeFIFO
A FIFO.
A class for storing, accessing and comparing dates.
Definition: OFDate.h:33
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:41
A class which provides management for files, e.g. reading contents of directories, deleting files, renaming files, etc.
Definition: OFFileManager.h:275
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
OFIRI * currentDirectoryIRI
The IRI of the current working directory.
Definition: OFFileManager.h:293
const OFFileAttributeKey OFFileExtendedAttributesNames
The names of the extended attributes as an OFArray of OFString.
const OFFileAttributeKey OFFileOwnerAccountID
The account ID of the owner of the file as an OFNumber.
const OFFileAttributeKey OFFileSymbolicLinkDestination
The destination of a symbolic link as an OFString.
const OFFileAttributeKey OFFileSize
The size of the file as an OFNumber.
OFDictionary * OFFileAttributes
A dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:100
const OFFileAttributeKey OFFileGroupOwnerAccountID
The account ID of the group owner of the file as an OFNumber.
A class for handling strings.
Definition: OFString.h:142
const OFFileAttributeKey OFFileStatusChangeDate
The last status change date of the file as an OFDate.
const OFFileAttributeKey OFFileType
The type of the file.
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:82
const OFFileAttributeKey OFFileOwnerAccountName
The account name of the owner of the file as an OFString.
OFFileManager * defaultManager()
Returns the default file manager.
Definition: OFFileManager.m:136
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:46
const OFFileAttributeType OFFileTypeDirectory
A directory.
const OFFileAttributeType OFFileTypeBlockSpecial
A block special file.
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:39
const OFFileAttributeType OFFileTypeCharacterSpecial
A character special file.
const OFFileAttributeKey OFFilePOSIXPermissions
The POSIX permissions of the file as an OFNumber.
A class for storing arbitrary data in an array.
Definition: OFData.h:45
const OFFileAttributeKey OFFileCreationDate
The creation date of the file as an OFDate.
const OFFileAttributeType OFFileTypeRegular
A regular file.
const OFFileAttributeType OFFileTypeUnknown
An unknown file type.
OFString * currentDirectoryPath
The path of the current working directory.
Definition: OFFileManager.h:286
const OFFileAttributeKey OFFileGroupOwnerAccountName
The account name of the group owner of the file as an OFString.
OFMutableDictionary * OFMutableFileAttributes
A mutable dictionary mapping keys of type OFFileAttributeKey to their attribute values.
Definition: OFFileManager.h:107
OFConstantString * OFFileAttributeType
The type of a file.
Definition: OFFileManager.h:94