2 * Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include <EntryOperationEngineBase.h>
17 BEntryOperationEngineBase::Entry::Entry(const char* path
)
28 BEntryOperationEngineBase::Entry::Entry(const BDirectory
& directory
,
31 fDirectory(&directory
),
40 BEntryOperationEngineBase::Entry::Entry(const BEntry
& entry
)
51 BEntryOperationEngineBase::Entry::Entry(const entry_ref
& entryRef
)
62 BEntryOperationEngineBase::Entry::Entry(const node_ref
& directoryRef
,
69 fDirectoryRef(&directoryRef
)
74 BEntryOperationEngineBase::Entry::~Entry()
80 BEntryOperationEngineBase::Entry::GetPath(BPath
& buffer
, const char*& _path
)
83 status_t error
= B_OK
;
86 error
= buffer
.SetTo(fEntry
);
87 } else if (fDirectory
!= NULL
) {
88 error
= buffer
.SetTo(fDirectory
, fPath
);
89 } else if (fEntryRef
!= NULL
) {
90 error
= buffer
.SetTo(fEntryRef
);
91 } else if (fDirectoryRef
!= NULL
) {
93 error
= directory
.SetTo(fDirectoryRef
);
95 error
= buffer
.SetTo(&directory
, fPath
);
96 } else if (fPath
!= NULL
) {
104 _path
= buffer
.Path();
110 BEntryOperationEngineBase::Entry::Path() const
114 if (GetPath(pathBuffer
, path
) == B_OK
)
115 return BString(path
);
121 BEntryOperationEngineBase::Entry::GetPathOrName(BString
& _path
) const
127 status_t error
= GetPath(buffer
, path
);
128 if (error
== B_NO_MEMORY
)
133 } else if (fEntry
!= NULL
) {
134 // GetPath() apparently failed, so just return the entry name.
135 _path
= fEntry
->Name();
136 } else if (fDirectory
!= NULL
|| fDirectoryRef
!= NULL
) {
137 if (fPath
!= NULL
&& fPath
[0] == '/') {
138 // absolute path -- just return it
141 // get the directory path
143 if (fDirectory
!= NULL
) {
144 error
= fDirectory
->GetEntry(&entry
);
146 BDirectory directory
;
147 error
= directory
.SetTo(fDirectoryRef
);
149 error
= directory
.GetEntry(&entry
);
152 if (error
!= B_OK
|| (error
= entry
.GetPath(&buffer
)) != B_OK
)
155 _path
= buffer
.Path();
157 // If we additionally have a relative path, append it.
158 if (!_path
.IsEmpty() && fPath
!= NULL
) {
159 int32 length
= _path
.Length();
160 _path
<< '/' << fPath
;
161 if (_path
.Length() < length
+ 2)
165 } else if (fEntryRef
!= NULL
) {
166 // Getting the actual path apparently failed, so just return the entry
168 _path
= fEntryRef
->name
;
169 } else if (fPath
!= NULL
)
172 return _path
.IsEmpty() ? B_NO_MEMORY
: B_OK
;
177 BEntryOperationEngineBase::Entry::PathOrName() const
180 return GetPathOrName(path
) == B_OK
? path
: BString();
184 } // namespace BPrivate