Skip to content

Commit ce28269

Browse files
committed
Hooked stream_metadata(..) with chown(..).
Part of facebook#3687. So far, only chown(..) in user-stream-wrapper has been hooked with stream_metadata(..) function. Similar to commit 1f55a08.
1 parent 744bca8 commit ce28269

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

hphp/runtime/base/user-file.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -518,5 +518,39 @@ bool UserFile::touch(const String& path, int64_t mtime, int64_t atime) {
518518
return false;
519519
}
520520

521+
bool UserFile::chown(const String& path, const Variant& user) {
522+
bool invoked = false;
523+
Variant ret;
524+
PackedArrayInit init(3);
525+
init.append(path);
526+
if (user.isString()) {
527+
init
528+
.append(2) // STREAM_META_OWNER_NAME
529+
.append(user.toString());
530+
ret = invoke(
531+
m_StreamMetadata,
532+
s_stream_metadata,
533+
init.toArray(),
534+
invoked
535+
);
536+
} else {
537+
init
538+
.append(3) // STREAM_META_OWNER
539+
.append(user.toInt32());
540+
ret = invoke(
541+
m_StreamMetadata,
542+
s_stream_metadata,
543+
init.toArray(),
544+
invoked
545+
);
546+
}
547+
if (invoked && ret.toBoolean() == true) {
548+
return true;
549+
}
550+
551+
raise_warning("\"%s::chown\" call failed", m_cls->name()->data());
552+
return false;
553+
}
554+
521555
///////////////////////////////////////////////////////////////////////////////
522556
}

hphp/runtime/base/user-file.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class UserFile : public File, public UserFSNode {
6262
bool mkdir(const String& path, int mode, int options);
6363
bool rmdir(const String& path, int options);
6464
bool touch(const String& path, int64_t mtime, int64_t atime);
65+
bool chown(const String& path, const Variant& user);
6566

6667
private:
6768
int urlStat(const String& path, struct stat* stat_sb, int flags = 0);

hphp/runtime/base/user-stream-wrapper.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,21 @@ Directory* UserStreamWrapper::opendir(const String& path) {
9292
return dir;
9393
}
9494

95+
///////////////////////////////////////////////////////////////////////////////
96+
// non-generic functions
97+
9598
bool UserStreamWrapper::touch(const String& path,
9699
int64_t mtime, int64_t atime) {
97100
auto file = NEWOBJ(UserFile)(m_cls);
98101
Resource wrapper(file);
99102
return file->touch(path, mtime, atime);
100103
}
101104

105+
bool UserStreamWrapper::chown(const String& path, const Variant& user) {
106+
auto file = NEWOBJ(UserFile)(m_cls);
107+
Resource wrapper(file);
108+
return file->chown(path, user);
109+
}
110+
102111
///////////////////////////////////////////////////////////////////////////////
103112
}

hphp/runtime/base/user-stream-wrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct UserStreamWrapper final : Stream::Wrapper {
3939
int rmdir(const String& path, int options) override;
4040
Directory* opendir(const String& path) override;
4141
bool touch(const String& path, int64_t mtime, int64_t atime);
42+
bool chown(const String& path, const Variant& user);
4243

4344
private:
4445
String m_name;

hphp/runtime/ext/ext_file.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,13 @@ static int get_uid(const Variant& user) {
11241124

11251125
bool f_chown(const String& filename, const Variant& user) {
11261126
CHECK_PATH_FALSE(filename, 1);
1127+
1128+
Stream::Wrapper* w = Stream::getWrapperFromURI(filename);
1129+
auto usw = dynamic_cast<UserStreamWrapper*>(w);
1130+
if (usw != nullptr) {
1131+
return usw->chown(filename, user);
1132+
}
1133+
11271134
int uid = get_uid(user);
11281135
if (uid == 0) return false;
11291136
CHECK_SYSTEM(chown(File::TranslatePath(filename).data(), uid, (gid_t)-1));

hphp/test/frameworks/results/vfsstream.expect

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ org\bovigo\vfs\vfsStreamWrapperTestCase::chmod
629629
org\bovigo\vfs\vfsStreamWrapperTestCase::chmodModifiesPermissions
630630
F
631631
org\bovigo\vfs\vfsStreamWrapperTestCase::chownChangesUser
632-
F
632+
.
633633
org\bovigo\vfs\vfsStreamWrapperTestCase::chownDoesNotWorkOnVfsStreamUrls
634634
.
635635
org\bovigo\vfs\vfsStreamWrapperTestCase::directoriesAndNonExistingFilesAreNeverExecutable

0 commit comments

Comments
 (0)