xref: /haiku/headers/os/package/hpkg/PackageEntry.h (revision c823de957be1c2c1a7d0c79194e2a3321ec9073b)
1 /*
2  * Copyright 2009,2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_H_
6 #define _PACKAGE__HPKG__PACKAGE_ENTRY_H_
7 
8 
9 #include <sys/stat.h>
10 
11 #include <package/hpkg/PackageData.h>
12 
13 
14 namespace BPackageKit {
15 
16 namespace BHPKG {
17 
18 
19 class BPackageEntry {
20 public:
21 								BPackageEntry(BPackageEntry* parent,
22 									const char* name);
23 
Parent()24 			const BPackageEntry*	Parent() const	{ return fParent; }
Name()25 			const char*			Name() const		{ return fName; }
UserToken()26 			void*				UserToken() const	{ return fUserToken; }
27 
Mode()28 			mode_t				Mode() const		{ return fMode; }
29 
AccessTime()30 			const timespec&		AccessTime() const
31 									{ return fAccessTime; }
ModifiedTime()32 			const timespec&		ModifiedTime() const
33 									{ return fModifiedTime; }
CreationTime()34 			const timespec&		CreationTime() const
35 									{ return fCreationTime; }
36 
Data()37 			BPackageData&		Data()	{ return fData; }
38 
SymlinkPath()39 			const char*			SymlinkPath() const	{ return fSymlinkPath; }
40 
SetUserToken(void * token)41 			void				SetUserToken(void* token)
42 									{ fUserToken = token; }
43 
44 			void				SetType(uint32 type);
45 			void				SetPermissions(uint32 permissions);
46 
SetAccessTime(uint32 seconds)47 			void				SetAccessTime(uint32 seconds)
48 									{ fAccessTime.tv_sec = seconds; }
SetAccessTimeNanos(uint32 nanos)49 			void				SetAccessTimeNanos(uint32 nanos)
50 									{ fAccessTime.tv_nsec = nanos; }
SetModifiedTime(uint32 seconds)51 			void				SetModifiedTime(uint32 seconds)
52 									{ fModifiedTime.tv_sec = seconds; }
SetModifiedTimeNanos(uint32 nanos)53 			void				SetModifiedTimeNanos(uint32 nanos)
54 									{ fModifiedTime.tv_nsec = nanos; }
SetCreationTime(uint32 seconds)55 			void				SetCreationTime(uint32 seconds)
56 									{ fCreationTime.tv_sec = seconds; }
SetCreationTimeNanos(uint32 nanos)57 			void				SetCreationTimeNanos(uint32 nanos)
58 									{ fCreationTime.tv_nsec = nanos; }
59 
SetSymlinkPath(const char * path)60 			void				SetSymlinkPath(const char* path)
61 									{ fSymlinkPath = path; }
62 private:
63 			BPackageEntry*		fParent;
64 			const char*			fName;
65 			void*				fUserToken;
66 			mode_t				fMode;
67 			timespec			fAccessTime;
68 			timespec			fModifiedTime;
69 			timespec			fCreationTime;
70 			BPackageData		fData;
71 			const char*			fSymlinkPath;
72 };
73 
74 
75 inline void
SetType(uint32 type)76 BPackageEntry::SetType(uint32 type)
77 {
78 	fMode = (fMode & ~(uint32)S_IFMT) | (type & S_IFMT);
79 }
80 
81 
82 inline void
SetPermissions(uint32 permissions)83 BPackageEntry::SetPermissions(uint32 permissions)
84 {
85 	fMode = (fMode & ~(uint32)ALLPERMS) | (permissions & ALLPERMS);
86 }
87 
88 
89 }	// namespace BHPKG
90 
91 }	// namespace BPackageKit
92 
93 
94 #endif	// _PACKAGE__HPKG__PACKAGE_ENTRY_H_
95