{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/xcbuild/pulls/comments/86868368","pull_request_review_id":7503063,"id":86868368,"diff_hunk":"@@ -17,21 +17,100 @@ using libutil::Filesystem;\n using libutil::FSUtil;\n \n bool Filesystem::\n-enumerateRecursive(\n-    std::string const &path,\n-    std::function<bool(std::string const &)> const &cb) const\n+copyFile(std::string const &from, std::string const &to)\n {\n-    this->enumerateDirectory(path, [&](std::string const &filename) -> void {\n-        std::string full = path + \"/\" + filename;\n-        cb(full);\n-    });\n-\n-    this->enumerateDirectory(path, [&](std::string const &filename) -> void {\n-        std::string full = path + \"/\" + filename;\n-        if (this->isDirectory(full) && !this->isSymbolicLink(full)) {\n-            this->enumerateRecursive(full, cb);\n+    std::vector<uint8_t> contents;\n+\n+    if (!this->read(&contents, from)) {\n+        return false;\n+    }\n+\n+    if (!this->write(contents, to)) {\n+        return false;\n+    }\n+\n+    return true;\n+}\n+\n+bool Filesystem::\n+copySymbolicLink(std::string const &from, std::string const &to)\n+{\n+    ext::optional<std::string> target = this->readSymbolicLink(from);\n+    if (!target) {\n+        return false;\n+    }\n+\n+    /*\n+     * Remove any existing symbolic link to overwrite, in the same way that copying\n+     * a file overwrites an existing file at the same path, but not a directory.\n+     */\n+    if (this->isSymbolicLink(to)) {\n+        if (!this->removeSymbolicLink(to)) {\n+            return false;\n+        }\n+    }\n+\n+    if (!this->writeSymbolicLink(to, *target)) {\n+        return false;\n+    }\n+\n+    return true;\n+}\n+\n+bool Filesystem::\n+copyDirectory(std::string const &from, std::string const &to, bool recursive)\n+{\n+    if (!this->isDirectory(from)) {\n+        return false;\n+    }\n+\n+    /*\n+     * Remove any existing directory to overwrite, in the same way that copying\n+     * a file overwrites an existing file at the same path, but not a directory.\n+     */\n+    if (this->isDirectory(to)) {\n+        if (!this->removeDirectory(to, recursive)) {\n+            return false;\n         }\n-    });\n+    }\n+\n+    if (!this->createDirectory(to, false)) {\n+        return false;\n+    }\n+\n+    if (recursive) {\n+        bool success = true;\n+\n+        success &= this->readDirectory(from, recursive, [this, &from, &to, &success](std::string const &path) {\n+            std::string fromPath = from + \"/\" + path;\n+            std::string toPath = to + \"/\" + path;\n+\n+            if (this->isSymbolicLink(fromPath)) {","path":"Libraries/libutil/Sources/Filesystem.cpp","position":85,"original_position":85,"commit_id":"3d0bd5090693d193767f5c78f4c590f7dae72e44","original_commit_id":"2f33424cb9aa708561d1a0ebacec1f68b1190307","user":{"login":"grp","id":163390,"avatar_url":"https://avatars.githubusercontent.com/u/163390?v=3","gravatar_id":"","url":"https://api.github.com/users/grp","html_url":"https://github.com/grp","followers_url":"https://api.github.com/users/grp/followers","following_url":"https://api.github.com/users/grp/following{/other_user}","gists_url":"https://api.github.com/users/grp/gists{/gist_id}","starred_url":"https://api.github.com/users/grp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grp/subscriptions","organizations_url":"https://api.github.com/users/grp/orgs","repos_url":"https://api.github.com/users/grp/repos","events_url":"https://api.github.com/users/grp/events{/privacy}","received_events_url":"https://api.github.com/users/grp/received_events","type":"User","site_admin":false},"body":"Yeah, probably should. Would also cut the number of `stat()` calls in here by 2/3...","created_at":"2016-11-07T21:04:51Z","updated_at":"2016-11-07T21:06:21Z","html_url":"https://github.com/facebook/xcbuild/pull/178#discussion_r86868368","pull_request_url":"https://api.github.com/repos/facebook/xcbuild/pulls/178","_links":{"self":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/comments/86868368"},"html":{"href":"https://github.com/facebook/xcbuild/pull/178#discussion_r86868368"},"pull_request":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/178"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/xcbuild/pulls/178","id":92305845,"html_url":"https://github.com/facebook/xcbuild/pull/178","diff_url":"https://github.com/facebook/xcbuild/pull/178.diff","patch_url":"https://github.com/facebook/xcbuild/pull/178.patch","issue_url":"https://api.github.com/repos/facebook/xcbuild/issues/178","number":178,"state":"open","locked":false,"title":"Filesystem functionality to replace /bin/cp, /bin/chmod, and chmod().","user":{"login":"grp","id":163390,"avatar_url":"https://avatars.githubusercontent.com/u/163390?v=3","gravatar_id":"","url":"https://api.github.com/users/grp","html_url":"https://github.com/grp","followers_url":"https://api.github.com/users/grp/followers","following_url":"https://api.github.com/users/grp/following{/other_user}","gists_url":"https://api.github.com/users/grp/gists{/gist_id}","starred_url":"https://api.github.com/users/grp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grp/subscriptions","organizations_url":"https://api.github.com/users/grp/orgs","repos_url":"https://api.github.com/users/grp/repos","events_url":"https://api.github.com/users/grp/events{/privacy}","received_events_url":"https://api.github.com/users/grp/received_events","type":"User","site_admin":false},"body":"Moves a bunch of stuff into the filesystem and cleans up the API to be more consistent. Includes tests for filesystem changes.","created_at":"2016-11-04T09:19:38Z","updated_at":"2016-11-07T21:06:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f4a7a8ee8c826b1177306731a2a40e51dbff575","assignee":{"login":"Ktwu","id":470651,"avatar_url":"https://avatars.githubusercontent.com/u/470651?v=3","gravatar_id":"","url":"https://api.github.com/users/Ktwu","html_url":"https://github.com/Ktwu","followers_url":"https://api.github.com/users/Ktwu/followers","following_url":"https://api.github.com/users/Ktwu/following{/other_user}","gists_url":"https://api.github.com/users/Ktwu/gists{/gist_id}","starred_url":"https://api.github.com/users/Ktwu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ktwu/subscriptions","organizations_url":"https://api.github.com/users/Ktwu/orgs","repos_url":"https://api.github.com/users/Ktwu/repos","events_url":"https://api.github.com/users/Ktwu/events{/privacy}","received_events_url":"https://api.github.com/users/Ktwu/received_events","type":"User","site_admin":false},"assignees":[{"login":"Ktwu","id":470651,"avatar_url":"https://avatars.githubusercontent.com/u/470651?v=3","gravatar_id":"","url":"https://api.github.com/users/Ktwu","html_url":"https://github.com/Ktwu","followers_url":"https://api.github.com/users/Ktwu/followers","following_url":"https://api.github.com/users/Ktwu/following{/other_user}","gists_url":"https://api.github.com/users/Ktwu/gists{/gist_id}","starred_url":"https://api.github.com/users/Ktwu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ktwu/subscriptions","organizations_url":"https://api.github.com/users/Ktwu/orgs","repos_url":"https://api.github.com/users/Ktwu/repos","events_url":"https://api.github.com/users/Ktwu/events{/privacy}","received_events_url":"https://api.github.com/users/Ktwu/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/xcbuild/pulls/178/commits","review_comments_url":"https://api.github.com/repos/facebook/xcbuild/pulls/178/comments","review_comment_url":"https://api.github.com/repos/facebook/xcbuild/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/xcbuild/issues/178/comments","statuses_url":"https://api.github.com/repos/facebook/xcbuild/statuses/3d0bd5090693d193767f5c78f4c590f7dae72e44","head":{"label":"facebook:grp/filesystem-additions","ref":"grp/filesystem-additions","sha":"3d0bd5090693d193767f5c78f4c590f7dae72e44","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":43019030,"name":"xcbuild","full_name":"facebook/xcbuild","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/xcbuild","description":"Xcode-compatible build tool.","fork":false,"url":"https://api.github.com/repos/facebook/xcbuild","forks_url":"https://api.github.com/repos/facebook/xcbuild/forks","keys_url":"https://api.github.com/repos/facebook/xcbuild/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/xcbuild/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/xcbuild/teams","hooks_url":"https://api.github.com/repos/facebook/xcbuild/hooks","issue_events_url":"https://api.github.com/repos/facebook/xcbuild/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/xcbuild/events","assignees_url":"https://api.github.com/repos/facebook/xcbuild/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/xcbuild/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/xcbuild/tags","blobs_url":"https://api.github.com/repos/facebook/xcbuild/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/xcbuild/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/xcbuild/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/xcbuild/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/xcbuild/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/xcbuild/languages","stargazers_url":"https://api.github.com/repos/facebook/xcbuild/stargazers","contributors_url":"https://api.github.com/repos/facebook/xcbuild/contributors","subscribers_url":"https://api.github.com/repos/facebook/xcbuild/subscribers","subscription_url":"https://api.github.com/repos/facebook/xcbuild/subscription","commits_url":"https://api.github.com/repos/facebook/xcbuild/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/xcbuild/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/xcbuild/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/xcbuild/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/xcbuild/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/xcbuild/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/xcbuild/merges","archive_url":"https://api.github.com/repos/facebook/xcbuild/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/xcbuild/downloads","issues_url":"https://api.github.com/repos/facebook/xcbuild/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/xcbuild/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/xcbuild/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/xcbuild/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/xcbuild/labels{/name}","releases_url":"https://api.github.com/repos/facebook/xcbuild/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/xcbuild/deployments","created_at":"2015-09-23T18:24:01Z","updated_at":"2016-11-07T11:48:25Z","pushed_at":"2016-11-07T19:35:08Z","git_url":"git://github.com/facebook/xcbuild.git","ssh_url":"git@github.com:facebook/xcbuild.git","clone_url":"https://github.com/facebook/xcbuild.git","svn_url":"https://github.com/facebook/xcbuild","homepage":null,"size":4275,"stargazers_count":1154,"watchers_count":1154,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":36,"forks":66,"open_issues":36,"watchers":1154,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"ef95e55f4732e26c83b4a8cb266f21c6897b309c","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":43019030,"name":"xcbuild","full_name":"facebook/xcbuild","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/xcbuild","description":"Xcode-compatible build tool.","fork":false,"url":"https://api.github.com/repos/facebook/xcbuild","forks_url":"https://api.github.com/repos/facebook/xcbuild/forks","keys_url":"https://api.github.com/repos/facebook/xcbuild/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/xcbuild/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/xcbuild/teams","hooks_url":"https://api.github.com/repos/facebook/xcbuild/hooks","issue_events_url":"https://api.github.com/repos/facebook/xcbuild/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/xcbuild/events","assignees_url":"https://api.github.com/repos/facebook/xcbuild/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/xcbuild/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/xcbuild/tags","blobs_url":"https://api.github.com/repos/facebook/xcbuild/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/xcbuild/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/xcbuild/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/xcbuild/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/xcbuild/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/xcbuild/languages","stargazers_url":"https://api.github.com/repos/facebook/xcbuild/stargazers","contributors_url":"https://api.github.com/repos/facebook/xcbuild/contributors","subscribers_url":"https://api.github.com/repos/facebook/xcbuild/subscribers","subscription_url":"https://api.github.com/repos/facebook/xcbuild/subscription","commits_url":"https://api.github.com/repos/facebook/xcbuild/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/xcbuild/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/xcbuild/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/xcbuild/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/xcbuild/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/xcbuild/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/xcbuild/merges","archive_url":"https://api.github.com/repos/facebook/xcbuild/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/xcbuild/downloads","issues_url":"https://api.github.com/repos/facebook/xcbuild/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/xcbuild/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/xcbuild/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/xcbuild/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/xcbuild/labels{/name}","releases_url":"https://api.github.com/repos/facebook/xcbuild/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/xcbuild/deployments","created_at":"2015-09-23T18:24:01Z","updated_at":"2016-11-07T11:48:25Z","pushed_at":"2016-11-07T19:35:08Z","git_url":"git://github.com/facebook/xcbuild.git","ssh_url":"git@github.com:facebook/xcbuild.git","clone_url":"https://github.com/facebook/xcbuild.git","svn_url":"https://github.com/facebook/xcbuild","homepage":null,"size":4275,"stargazers_count":1154,"watchers_count":1154,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":36,"forks":66,"open_issues":36,"watchers":1154,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/178"},"html":{"href":"https://github.com/facebook/xcbuild/pull/178"},"issue":{"href":"https://api.github.com/repos/facebook/xcbuild/issues/178"},"comments":{"href":"https://api.github.com/repos/facebook/xcbuild/issues/178/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/178/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/xcbuild/pulls/178/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/xcbuild/statuses/3d0bd5090693d193767f5c78f4c590f7dae72e44"}}}}
{"actor":{"display_login":"grp"}}