ObjFW  Check-in [639dd9c244]

Overview
Comment:Add -[OFFileManager getUID:GID:ofItemAtPath:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 639dd9c2440a065333ab78f8ce627f4dd901ef783eb5b1f826c07c95d754ed5b
User & Date: js on 2017-08-06 22:21:58
Other Links: manifest | tags
Context
2017-08-06
22:24
ofzip: Include UID & GID in tar archives check-in: dc0a020230 user: js tags: trunk
22:21
Add -[OFFileManager getUID:GID:ofItemAtPath:] check-in: 639dd9c244 user: js tags: trunk
22:09
OFTarArchiveEntry: Add UID and GID check-in: 8c00ffb513 user: js tags: trunk
Changes

Modified src/OFFileManager.h from [1f6e451528] to [b4c0bf6d7e].

178
179
180
181
182
183
184











185
186
187
188
189


190
191
192
193
194
195
196
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







+
+
+
+
+
+
+
+
+
+
+



-
-
+
+







 * @param permissions The new permissions for the item
 */
- (void)changePermissionsOfItemAtPath: (OFString *)path
			  permissions: (uint16_t)permissions;
#endif

#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
/*!
 * @brief Get the UID and GID of the specified item.
 *
 * @param UID A pointer to an uint16_t to store the UID, or NULL
 * @param GID A pointer to an uint16_t to store the GID, or NULL
 * @param path The path to the item whose UID and GID should be retrieved
 */
- (void)getUID: (nullable uint16_t *)UID
	   GID: (nullable uint16_t *)GID
  ofItemAtPath: (OFString *)path;

/*!
 * @brief Get the owner and group of the specified item.
 *
 * @param owner A pointer to an `OFString *` to store the owner, or nil
 * @param group A pointer to an `OFString *` to store the group, or nil
 * @param owner A pointer to an `OFString *` to store the owner, or NULL
 * @param group A pointer to an `OFString *` to store the group, or NULL
 * @param path The path to the item whose owner and group should be retrieved
 */
- (void)getOwner: (OFString *__autoreleasing _Nonnull *_Nullable)owner
	   group: (OFString *__autoreleasing _Nonnull *_Nullable)group
    ofItemAtPath: (OFString *)path;

/*!

Modified src/OFFileManager.m from [bd75067227] to [6c0ff405f2].

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
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







-
-
-
+
+
+










+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+






-
+







		    exceptionWithPath: path
			  permissions: permissions
				errNo: errno];
}
#endif

#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
- (void)getOwner: (OFString **)owner
	   group: (OFString **)group
    ofItemAtPath: (OFString *)path
- (void)getUID: (uint16_t *)UID
	   GID: (uint16_t *)GID
  ofItemAtPath: (OFString *)path
{
	of_stat_t s;

	if (path == nil)
		@throw [OFInvalidArgumentException exception];

	if (of_stat(path, &s) != 0)
		@throw [OFStatItemFailedException exceptionWithPath: path
							      errNo: errno];

	if (UID != NULL)
		*UID = s.st_uid;
	if (GID != NULL)
		*GID = s.st_gid;
}

- (void)getOwner: (OFString **)owner
	   group: (OFString **)group
    ofItemAtPath: (OFString *)path
{
	uint16_t UID, GID;

	[self	  getUID: &UID
		     GID: &GID
	    ofItemAtPath: path];

# ifdef OF_HAVE_THREADS
	[passwdMutex lock];
	@try {
# endif
		of_string_encoding_t encoding = [OFLocalization encoding];

		if (owner != NULL) {
			struct passwd *passwd = getpwuid(s.st_uid);
			struct passwd *passwd = getpwuid(UID);

			*owner = [OFString stringWithCString: passwd->pw_name
						    encoding: encoding];
		}

		if (group != NULL) {
			struct group *group_ = getgrgid(s.st_gid);
			struct group *group_ = getgrgid(GID);

			*group = [OFString stringWithCString: group_->gr_name
						    encoding: encoding];
		}
# ifdef OF_HAVE_THREADS
	} @finally {
		[passwdMutex unlock];