storage/nfs: move code to Copy()

This commit is contained in:
Max Kellermann 2014-10-06 21:45:40 +02:00
parent 07b50f6c69
commit f0bb5b84f9

View File

@ -115,16 +115,9 @@ NfsStorage::MapToRelativeUTF8(const char *uri_utf8) const
return PathTraitsUTF8::Relative(base.c_str(), uri_utf8); return PathTraitsUTF8::Relative(base.c_str(), uri_utf8);
} }
static bool static void
GetInfo(nfs_context *ctx, const char *path, FileInfo &info, Error &error) Copy(FileInfo &info, const struct stat &st)
{ {
struct stat st;
int result = nfs_stat(ctx, path, &st);
if (result < 0) {
error.SetErrno(-result, "nfs_stat() failed");
return false;
}
if (S_ISREG(st.st_mode)) if (S_ISREG(st.st_mode))
info.type = FileInfo::Type::REGULAR; info.type = FileInfo::Type::REGULAR;
else if (S_ISDIR(st.st_mode)) else if (S_ISDIR(st.st_mode))
@ -136,6 +129,19 @@ GetInfo(nfs_context *ctx, const char *path, FileInfo &info, Error &error)
info.mtime = st.st_mtime; info.mtime = st.st_mtime;
info.device = st.st_dev; info.device = st.st_dev;
info.inode = st.st_ino; info.inode = st.st_ino;
}
static bool
GetInfo(nfs_context *ctx, const char *path, FileInfo &info, Error &error)
{
struct stat st;
int result = nfs_stat(ctx, path, &st);
if (result < 0) {
error.SetErrno(-result, "nfs_stat() failed");
return false;
}
Copy(info, st);
return true; return true;
} }
@ -201,13 +207,10 @@ NfsDirectoryReader::Read()
return nullptr; return nullptr;
} }
bool static void
NfsDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info, Copy(FileInfo &info, const struct nfsdirent &ent)
gcc_unused Error &error)
{ {
assert(ent != nullptr); switch (ent.type) {
switch (ent->type) {
case NF3REG: case NF3REG:
info.type = FileInfo::Type::REGULAR; info.type = FileInfo::Type::REGULAR;
break; break;
@ -221,10 +224,19 @@ NfsDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
break; break;
} }
info.size = ent->size; info.size = ent.size;
info.mtime = ent->mtime.tv_sec; info.mtime = ent.mtime.tv_sec;
info.device = 0; info.device = 0;
info.inode = ent->inode; info.inode = ent.inode;
}
bool
NfsDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
gcc_unused Error &error)
{
assert(ent != nullptr);
Copy(info, *ent);
return true; return true;
} }