1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "PackageNode.h"
8
9#include <stdlib.h>
10#include <string.h>
11
12#include "DebugSupport.h"
13
14
15PackageNode::PackageNode(Package* package, mode_t mode)
16	:
17	fPackage(package),
18	fParent(NULL),
19	fName(NULL),
20	fMode(mode),
21	fUserID(0),
22	fGroupID(0)
23{
24}
25
26
27PackageNode::~PackageNode()
28{
29	while (PackageNodeAttribute* attribute = fAttributes.RemoveHead())
30		delete attribute;
31
32	free(fName);
33}
34
35
36status_t
37PackageNode::Init(PackageDirectory* parent, const char* name)
38{
39	fParent = parent;
40	fName = strdup(name);
41	if (fName == NULL)
42		RETURN_ERROR(B_NO_MEMORY);
43
44	return B_OK;
45}
46
47
48status_t
49PackageNode::VFSInit(dev_t deviceID, ino_t nodeID)
50{
51	return B_OK;
52}
53
54
55void
56PackageNode::VFSUninit()
57{
58}
59
60
61off_t
62PackageNode::FileSize() const
63{
64	return 0;
65}
66
67
68void
69PackageNode::AddAttribute(PackageNodeAttribute* attribute)
70{
71	fAttributes.Add(attribute);
72}
73
74
75void
76PackageNode::RemoveAttribute(PackageNodeAttribute* attribute)
77{
78	fAttributes.Remove(attribute);
79}
80
81
82PackageNodeAttribute*
83PackageNode::FindAttribute(const char* name) const
84{
85	for (PackageNodeAttributeList::ConstIterator it = fAttributes.GetIterator();
86			PackageNodeAttribute* attribute = it.Next();) {
87		if (strcmp(attribute->Name(), name) == 0)
88			return attribute;
89	}
90
91	return NULL;
92}
93
94
95void
96PackageNode::UnsetIndexCookie(void* attributeCookie)
97{
98	((PackageNodeAttribute*)attributeCookie)->SetIndexCookie(NULL);
99}
100