xref: /haiku/src/kits/storage/EntryOperationEngineBase.cpp (revision 37fedaf8494b34aad811abcc49e79aa32943f880)
1 /*
2  * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <EntryOperationEngineBase.h>
8 
9 #include <Directory.h>
10 #include <Entry.h>
11 #include <Path.h>
12 
13 
14 namespace BPrivate {
15 
16 
17 BEntryOperationEngineBase::Entry::Entry(const char* path)
18 	:
19 	fDirectory(NULL),
20 	fPath(path),
21 	fEntry(NULL),
22 	fEntryRef(NULL)
23 
24 {
25 }
26 
27 
28 BEntryOperationEngineBase::Entry::Entry(const BDirectory& directory, const char* path)
29 	:
30 	fDirectory(&directory),
31 	fPath(path),
32 	fEntry(NULL),
33 	fEntryRef(NULL)
34 {
35 }
36 
37 
38 BEntryOperationEngineBase::Entry::Entry(const BEntry& entry)
39 	:
40 	fDirectory(NULL),
41 	fPath(NULL),
42 	fEntry(&entry),
43 	fEntryRef(NULL)
44 {
45 }
46 
47 
48 BEntryOperationEngineBase::Entry::Entry(const entry_ref& entryRef)
49 	:
50 	fDirectory(NULL),
51 	fPath(NULL),
52 	fEntry(NULL),
53 	fEntryRef(&entryRef)
54 {
55 }
56 
57 
58 BEntryOperationEngineBase::Entry::~Entry()
59 {
60 }
61 
62 
63 status_t
64 BEntryOperationEngineBase::Entry::GetPath(BPath& buffer, const char*& _path)
65 	const
66 {
67 	status_t error = B_OK;
68 
69 	if (fEntry != NULL) {
70 		error = buffer.SetTo(fEntry);
71 	} else if (fDirectory != NULL) {
72 		error = buffer.SetTo(fDirectory, fPath);
73 	} else if (fEntryRef != NULL) {
74 		error = buffer.SetTo(fEntryRef);
75 	} else if (fPath != NULL) {
76 		_path = fPath;
77 		return B_OK;
78 	}
79 
80 	if (error != B_OK)
81 		return error;
82 
83 	_path = buffer.Path();
84 	return B_OK;
85 }
86 
87 
88 BString
89 BEntryOperationEngineBase::Entry::Path() const
90 {
91 	BPath pathBuffer;
92 	const char* path;
93 	if (GetPath(pathBuffer, path) == B_OK)
94 		return BString(path);
95 	return BString();
96 }
97 
98 
99 } // namespace BPrivate
100