BCopyEngine: Add base class BEntryOperationEngineBase
It contains a helper class Entry, which allows to generalize the BCopyEngine::CopyEntry() parameters.
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <EntryOperationEngineBase.h>
|
||||||
|
|
||||||
|
|
||||||
class BFile;
|
class BFile;
|
||||||
@@ -21,7 +21,7 @@ class BNode;
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
class BCopyEngine {
|
class BCopyEngine : public BEntryOperationEngineBase {
|
||||||
public:
|
public:
|
||||||
class BController;
|
class BController;
|
||||||
|
|
||||||
@@ -43,8 +43,8 @@ public:
|
|||||||
BCopyEngine& AddFlags(uint32 flags);
|
BCopyEngine& AddFlags(uint32 flags);
|
||||||
BCopyEngine& RemoveFlags(uint32 flags);
|
BCopyEngine& RemoveFlags(uint32 flags);
|
||||||
|
|
||||||
status_t CopyEntry(const char* sourcePath,
|
status_t CopyEntry(const Entry& sourceEntry,
|
||||||
const char* destPath);
|
const Entry& destEntry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _CopyEntry(const char* sourcePath,
|
status_t _CopyEntry(const char* sourcePath,
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ingo Weinhold <[email protected]>
|
||||||
|
*/
|
||||||
|
#ifndef _ENTRY_OPERATION_ENGINE_BASE_H
|
||||||
|
#define _ENTRY_OPERATION_ENGINE_BASE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BDirectory;
|
||||||
|
class BEntry;
|
||||||
|
class BPath;
|
||||||
|
|
||||||
|
struct entry_ref;
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
class BEntryOperationEngineBase {
|
||||||
|
public:
|
||||||
|
class Entry;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BEntryOperationEngineBase::Entry {
|
||||||
|
public:
|
||||||
|
Entry(const char* path);
|
||||||
|
Entry(const BDirectory& directory,
|
||||||
|
const char* path = NULL);
|
||||||
|
Entry(const BEntry& entry);
|
||||||
|
Entry(const entry_ref& entryRef);
|
||||||
|
~Entry();
|
||||||
|
|
||||||
|
status_t GetPath(BPath& buffer, const char*& _path)
|
||||||
|
const;
|
||||||
|
BString Path() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const BDirectory* fDirectory;
|
||||||
|
const char* fPath;
|
||||||
|
const BEntry* fEntry;
|
||||||
|
const entry_ref* fEntryRef;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _ENTRY_OPERATION_ENGINE_BASE_H
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
|
||||||
#include <SymLink.h>
|
#include <SymLink.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
@@ -97,7 +96,7 @@ BCopyEngine::RemoveFlags(uint32 flags)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BCopyEngine::CopyEntry(const char* sourcePath, const char* destPath)
|
BCopyEngine::CopyEntry(const Entry& sourceEntry, const Entry& destEntry)
|
||||||
{
|
{
|
||||||
if (fBuffer == NULL) {
|
if (fBuffer == NULL) {
|
||||||
fBuffer = new(std::nothrow) char[kDefaultBufferSize];
|
fBuffer = new(std::nothrow) char[kDefaultBufferSize];
|
||||||
@@ -112,6 +111,18 @@ BCopyEngine::CopyEntry(const char* sourcePath, const char* destPath)
|
|||||||
fBufferSize = kDefaultBufferSize;
|
fBufferSize = kDefaultBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BPath sourcePathBuffer;
|
||||||
|
const char* sourcePath;
|
||||||
|
status_t error = sourceEntry.GetPath(sourcePathBuffer, sourcePath);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
BPath destPathBuffer;
|
||||||
|
const char* destPath;
|
||||||
|
error = destEntry.GetPath(destPathBuffer, destPath);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
return _CopyEntry(sourcePath, destPath);
|
return _CopyEntry(sourcePath, destPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <EntryOperationEngineBase.h>
|
||||||
|
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
BEntryOperationEngineBase::Entry::Entry(const char* path)
|
||||||
|
:
|
||||||
|
fDirectory(NULL),
|
||||||
|
fPath(path),
|
||||||
|
fEntry(NULL),
|
||||||
|
fEntryRef(NULL)
|
||||||
|
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BEntryOperationEngineBase::Entry::Entry(const BDirectory& directory, const char* path)
|
||||||
|
:
|
||||||
|
fDirectory(&directory),
|
||||||
|
fPath(path),
|
||||||
|
fEntry(NULL),
|
||||||
|
fEntryRef(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BEntryOperationEngineBase::Entry::Entry(const BEntry& entry)
|
||||||
|
:
|
||||||
|
fDirectory(NULL),
|
||||||
|
fPath(NULL),
|
||||||
|
fEntry(&entry),
|
||||||
|
fEntryRef(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BEntryOperationEngineBase::Entry::Entry(const entry_ref& entryRef)
|
||||||
|
:
|
||||||
|
fDirectory(NULL),
|
||||||
|
fPath(NULL),
|
||||||
|
fEntry(NULL),
|
||||||
|
fEntryRef(&entryRef)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BEntryOperationEngineBase::Entry::~Entry()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BEntryOperationEngineBase::Entry::GetPath(BPath& buffer, const char*& _path)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
status_t error;
|
||||||
|
|
||||||
|
if (fEntry != NULL) {
|
||||||
|
error = buffer.SetTo(fEntry);
|
||||||
|
} else if (fDirectory != NULL) {
|
||||||
|
error = buffer.SetTo(fDirectory, fPath);
|
||||||
|
} else if (fEntryRef != NULL) {
|
||||||
|
error = buffer.SetTo(fEntryRef);
|
||||||
|
} else if (fPath != NULL) {
|
||||||
|
_path = fPath;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
_path = buffer.Path();
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
BEntryOperationEngineBase::Entry::Path() const
|
||||||
|
{
|
||||||
|
BPath pathBuffer;
|
||||||
|
const char* path;
|
||||||
|
if (GetPath(pathBuffer, path) == B_OK)
|
||||||
|
return BString(path);
|
||||||
|
return BString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
@@ -26,6 +26,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
DriverSettings.cpp
|
DriverSettings.cpp
|
||||||
Entry.cpp
|
Entry.cpp
|
||||||
EntryList.cpp
|
EntryList.cpp
|
||||||
|
EntryOperationEngineBase.cpp
|
||||||
File.cpp
|
File.cpp
|
||||||
FileDescriptorIO.cpp
|
FileDescriptorIO.cpp
|
||||||
FileIO.cpp
|
FileIO.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user