Move PackageLinkDirectory::Link to own file
And rename it to PackageLinkSymlink.
This commit is contained in:
parent
106c8c6153
commit
c6dd220780
@ -26,6 +26,7 @@ HAIKU_PACKAGE_FS_SOURCES =
|
||||
PackageLinkDirectory.cpp
|
||||
PackageLinksDirectory.cpp
|
||||
PackageLinksListener.cpp
|
||||
PackageLinkSymlink.cpp
|
||||
PackageNode.cpp
|
||||
PackageNodeAttribute.cpp
|
||||
PackageSymlink.cpp
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "PackageLinkDirectory.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
|
||||
#include <NodeMonitor.h>
|
||||
@ -22,120 +21,6 @@
|
||||
|
||||
|
||||
static const char* const kSelfLinkName = ".self";
|
||||
static const char* const kSystemLinkPath = "../..";
|
||||
static const char* const kCommonLinkPath = "../../../common";
|
||||
static const char* const kHomeLinkPath = "../../../home/config";
|
||||
|
||||
|
||||
static const char*
|
||||
link_path_for_mount_type(MountType type)
|
||||
{
|
||||
switch (type) {
|
||||
case MOUNT_TYPE_SYSTEM:
|
||||
return kSystemLinkPath;
|
||||
case MOUNT_TYPE_COMMON:
|
||||
return kCommonLinkPath;
|
||||
case MOUNT_TYPE_HOME:
|
||||
return kHomeLinkPath;
|
||||
case MOUNT_TYPE_CUSTOM:
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - SelfLink
|
||||
|
||||
|
||||
class PackageLinkDirectory::SelfLink : public Node {
|
||||
public:
|
||||
SelfLink(Package* package)
|
||||
:
|
||||
Node(0)
|
||||
{
|
||||
Update(package);
|
||||
}
|
||||
|
||||
virtual ~SelfLink()
|
||||
{
|
||||
}
|
||||
|
||||
void Update(Package* package)
|
||||
{
|
||||
fLinkPath = link_path_for_mount_type(
|
||||
package->Domain()->Volume()->MountType());
|
||||
get_real_time(fModifiedTime);
|
||||
}
|
||||
|
||||
virtual mode_t Mode() const
|
||||
{
|
||||
return S_IFLNK | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH
|
||||
| S_IXOTH;
|
||||
}
|
||||
|
||||
virtual uid_t UserID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual gid_t GroupID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual timespec ModifiedTime() const
|
||||
{
|
||||
return fModifiedTime;
|
||||
}
|
||||
|
||||
virtual off_t FileSize() const
|
||||
{
|
||||
return strlen(fLinkPath);
|
||||
}
|
||||
|
||||
virtual status_t Read(off_t offset, void* buffer, size_t* bufferSize)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
virtual status_t Read(io_request* request)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
virtual status_t ReadSymlink(void* buffer, size_t* bufferSize)
|
||||
{
|
||||
size_t toCopy = std::min(strlen(fLinkPath), *bufferSize);
|
||||
memcpy(buffer, fLinkPath, toCopy);
|
||||
*bufferSize = toCopy;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t OpenAttributeDirectory(AttributeDirectoryCookie*& _cookie)
|
||||
{
|
||||
AttributeDirectoryCookie* cookie
|
||||
= new(std::nothrow) EmptyAttributeDirectoryCookie;
|
||||
if (cookie == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
_cookie = cookie;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t OpenAttribute(const char* name, int openMode,
|
||||
AttributeCookie*& _cookie)
|
||||
{
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
private:
|
||||
timespec fModifiedTime;
|
||||
const char* fLinkPath;
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - PackageLinkDirectory
|
||||
|
||||
|
||||
PackageLinkDirectory::PackageLinkDirectory()
|
||||
@ -327,7 +212,7 @@ PackageLinkDirectory::_Update(PackageLinksListener* listener)
|
||||
|
||||
// create/update self link
|
||||
if (fSelfLink == NULL) {
|
||||
fSelfLink = new(std::nothrow) SelfLink(package);
|
||||
fSelfLink = new(std::nothrow) Link(package);
|
||||
if (fSelfLink == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
@ -344,12 +229,7 @@ PackageLinkDirectory::_Update(PackageLinksListener* listener)
|
||||
}
|
||||
} else {
|
||||
NodeWriteLocker selfLinkLocker(fSelfLink);
|
||||
fSelfLink->Update(package);
|
||||
|
||||
if (listener != NULL) {
|
||||
listener->PackageLinkNodeChanged(fSelfLink,
|
||||
B_STAT_SIZE | B_STAT_MODIFICATION_TIME);
|
||||
}
|
||||
fSelfLink->Update(package, listener);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "Directory.h"
|
||||
#include "Package.h"
|
||||
#include "PackageLinkSymlink.h"
|
||||
|
||||
|
||||
class PackageLinksListener;
|
||||
@ -44,7 +45,7 @@ public:
|
||||
{ return fPackages.IsEmpty(); }
|
||||
|
||||
private:
|
||||
class SelfLink;
|
||||
typedef PackageLinkSymlink Link;
|
||||
|
||||
private:
|
||||
status_t _Update(PackageLinksListener* listener);
|
||||
@ -52,7 +53,7 @@ private:
|
||||
private:
|
||||
timespec fModifiedTime;
|
||||
PackageList fPackages;
|
||||
SelfLink* fSelfLink;
|
||||
Link* fSelfLink;
|
||||
};
|
||||
|
||||
|
||||
|
154
src/add-ons/kernel/file_systems/packagefs/PackageLinkSymlink.cpp
Normal file
154
src/add-ons/kernel/file_systems/packagefs/PackageLinkSymlink.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "PackageLinkSymlink.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <NodeMonitor.h>
|
||||
|
||||
#include "EmptyAttributeDirectoryCookie.h"
|
||||
#include "DebugSupport.h"
|
||||
#include "PackageLinksListener.h"
|
||||
#include "Utils.h"
|
||||
#include "Volume.h"
|
||||
|
||||
|
||||
static const char* const kSystemLinkPath = "../..";
|
||||
static const char* const kCommonLinkPath = "../../../common";
|
||||
static const char* const kHomeLinkPath = "../../../home/config";
|
||||
|
||||
|
||||
static const char*
|
||||
link_path_for_mount_type(MountType type)
|
||||
{
|
||||
switch (type) {
|
||||
case MOUNT_TYPE_SYSTEM:
|
||||
return kSystemLinkPath;
|
||||
case MOUNT_TYPE_COMMON:
|
||||
return kCommonLinkPath;
|
||||
case MOUNT_TYPE_HOME:
|
||||
return kHomeLinkPath;
|
||||
case MOUNT_TYPE_CUSTOM:
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
PackageLinkSymlink::PackageLinkSymlink(Package* package)
|
||||
:
|
||||
Node(0)
|
||||
{
|
||||
Update(package, NULL);
|
||||
}
|
||||
|
||||
|
||||
PackageLinkSymlink::~PackageLinkSymlink()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLinkSymlink::Update(Package* package, PackageLinksListener* listener)
|
||||
{
|
||||
if (package != NULL) {
|
||||
fLinkPath = link_path_for_mount_type(
|
||||
package->Domain()->Volume()->MountType());
|
||||
} else
|
||||
fLinkPath = "?";
|
||||
|
||||
get_real_time(fModifiedTime);
|
||||
|
||||
if (listener != NULL) {
|
||||
listener->PackageLinkNodeChanged(this,
|
||||
B_STAT_SIZE | B_STAT_MODIFICATION_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mode_t
|
||||
PackageLinkSymlink::Mode() const
|
||||
{
|
||||
return S_IFLNK | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
}
|
||||
|
||||
|
||||
uid_t
|
||||
PackageLinkSymlink::UserID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
gid_t
|
||||
PackageLinkSymlink::GroupID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
timespec
|
||||
PackageLinkSymlink::ModifiedTime() const
|
||||
{
|
||||
return fModifiedTime;
|
||||
}
|
||||
|
||||
|
||||
off_t
|
||||
PackageLinkSymlink::FileSize() const
|
||||
{
|
||||
return strlen(fLinkPath);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageLinkSymlink::Read(off_t offset, void* buffer, size_t* bufferSize)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageLinkSymlink::Read(io_request* request)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageLinkSymlink::ReadSymlink(void* buffer, size_t* bufferSize)
|
||||
{
|
||||
size_t toCopy = std::min(strlen(fLinkPath), *bufferSize);
|
||||
memcpy(buffer, fLinkPath, toCopy);
|
||||
*bufferSize = toCopy;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageLinkSymlink::OpenAttributeDirectory(AttributeDirectoryCookie*& _cookie)
|
||||
{
|
||||
AttributeDirectoryCookie* cookie
|
||||
= new(std::nothrow) EmptyAttributeDirectoryCookie;
|
||||
if (cookie == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
_cookie = cookie;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageLinkSymlink::OpenAttribute(const char* name, int openMode,
|
||||
AttributeCookie*& _cookie)
|
||||
{
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_LINK_SYMLINK_H
|
||||
#define PACKAGE_LINK_SYMLINK_H
|
||||
|
||||
|
||||
#include "Node.h"
|
||||
|
||||
|
||||
class Package;
|
||||
class PackageLinksListener;
|
||||
|
||||
|
||||
class PackageLinkSymlink : public Node {
|
||||
public:
|
||||
PackageLinkSymlink(Package* package);
|
||||
virtual ~PackageLinkSymlink();
|
||||
|
||||
void Update(Package* package,
|
||||
PackageLinksListener* listener);
|
||||
|
||||
virtual mode_t Mode() const;
|
||||
virtual uid_t UserID() const;
|
||||
virtual gid_t GroupID() const;
|
||||
virtual timespec ModifiedTime() const;
|
||||
virtual off_t FileSize() const;
|
||||
|
||||
virtual status_t Read(off_t offset, void* buffer,
|
||||
size_t* bufferSize);
|
||||
virtual status_t Read(io_request* request);
|
||||
|
||||
virtual status_t ReadSymlink(void* buffer, size_t* bufferSize);
|
||||
|
||||
virtual status_t OpenAttributeDirectory(
|
||||
AttributeDirectoryCookie*& _cookie);
|
||||
virtual status_t OpenAttribute(const char* name, int openMode,
|
||||
AttributeCookie*& _cookie);
|
||||
|
||||
private:
|
||||
timespec fModifiedTime;
|
||||
const char* fLinkPath;
|
||||
};
|
||||
|
||||
|
||||
#endif // PACKAGE_LINK_SYMLINK_H
|
Loading…
Reference in New Issue
Block a user