summaryrefslogtreecommitdiff
path: root/src/repo.cpp
blob: 299f2ce404d93e5355c672e32188a0b00a6855f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <Ice/ObjectAdapter.h>
#include <sys/stat.h>
#include "repo.h"
#include "blob.h"
#include "dir.h"

GitFS::Repo::Repo() :
	repo(Git::RepositoryOpenBare("/usr/portage/.git")),
	commit(Git::CommitLookup(repo, Git::OidParse("97a435f30472eb941f96234d274b3aeb492e2793"))),
	tree(Git::TreeLookup(repo, *git_commit_tree_id(commit.get())))
{
}

void
GitFS::Repo::disconnect(const ::Ice::Current& current)
{
	current.adapter->remove(current.id);
}


NetFS::DirectoryPrxPtr
GitFS::Repo::opendir(ReqEnv, ::std::string path, const ::Ice::Current& ice)
{
	return Ice::uncheckedCast<NetFS::DirectoryV2Prx>(ice.adapter->addWithUUID(
				std::make_shared<Directory>(tree, path)));
}


NetFS::VFS
GitFS::Repo::statfs(ReqEnv, ::std::string, const ::Ice::Current&)
{
	return {};
}


int
GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&)
{
	if (mode & W_OK) return EACCES;
	if (path.empty()) return EINVAL;
	if (path == "/") return 0;

	try {
		auto e = Git::TreeEntryByPath(tree, path);
		const auto emode = git_tree_entry_filemode(e.get());

		if (S_ISDIR(emode)) return 0;
		if (mode & R_OK && !(S_IRUSR & emode)) return EACCES;
		if (mode & X_OK && !(S_IXUSR & emode)) return EACCES;

		return 0;
	}
	catch (const Git::Error & e) {
		if (e.err == GIT_ENOTFOUND) {
			return ENOENT;
		}
		throw NetFS::SystemError(EIO);
	}
}


NetFS::Attr
GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&)
{
	NetFS::Attr a {};
	(void)path;
	a.ctime = a.atime = a.mtime = git_commit_time(commit.get());
	return a;
}


::std::string
GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current&)
{
	auto e = Git::TreeEntryByPath(tree, path);
	if (!e) throw NetFS::SystemError(ENOENT);
	const auto emode = git_tree_entry_filemode(e.get());
	if (!S_ISLNK(emode)) throw NetFS::SystemError(EINVAL);
	return {};
}


NetFS::FilePrxPtr
GitFS::Repo::open(ReqEnv, ::std::string path, int, const ::Ice::Current& ice)
{
	return Ice::uncheckedCast<NetFS::FilePrx>(ice.adapter->addWithUUID(
				std::make_shared<Blob>(repo, Git::TreeEntryByPath(tree, path))));
}


NetFS::FilePrxPtr
GitFS::Repo::create(ReqEnv, ::std::string, int, int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::truncate(ReqEnv, ::std::string, long long int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::unlink(ReqEnv, ::std::string, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::mkdir(ReqEnv, ::std::string, int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::rmdir(ReqEnv, ::std::string, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::mknod(ReqEnv, ::std::string, int, int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::symlink(ReqEnv, ::std::string, ::std::string, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::link(ReqEnv, ::std::string, ::std::string, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::rename(ReqEnv, ::std::string, ::std::string, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::chmod(ReqEnv, ::std::string, int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::chown(ReqEnv, ::std::string, int, int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}


void
GitFS::Repo::utimens(ReqEnv, ::std::string, long long int, long long int, long long int, long long int, const ::Ice::Current&)
{
	throw NetFS::SystemError(EROFS);
}