{"action":"created","comment":{"url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments/58703908","id":58703908,"diff_hunk":"@@ -104,64 +105,129 @@ static void KillCvmfs(const string &fqrn) {\n   ExecAsRoot(\"/bin/kill\", \"-9\", pid.c_str(), NULL);\n }\n \n-static bool ClearWorkingDir() {\n-  int retval;\n-  DIR *dirp = opendir(\".\");\n-  if (dirp == NULL)\n-    return false;\n-  platform_dirent64 *dirent;\n-  while ((dirent = platform_readdir(dirp)) != NULL) {\n-    if ((strcmp(dirent->d_name, \".\") == 0) ||\n-        (strcmp(dirent->d_name, \"..\") == 0))\n-    {\n-      continue;\n+class ScopedWorkingDirectory {\n+ public:\n+  explicit ScopedWorkingDirectory(const string &path)\n+    : previous_path_(GetCurrentWorkingDirectory())\n+    , directory_handle_(NULL)\n+  {\n+    ChangeDirectory(path);\n+    directory_handle_ = opendir(\".\");\n+  }\n+\n+  ~ScopedWorkingDirectory() {\n+    if (directory_handle_ != NULL) {\n+      closedir(directory_handle_);\n+    }\n+    ChangeDirectory(previous_path_);\n+  }\n+\n+  operator bool() const { return directory_handle_ != NULL; }\n+\n+  struct DirectoryEntry {\n+    bool   is_directory;\n+    string name;\n+  };\n+\n+  bool NextDirectoryEntry(DirectoryEntry *entry) {\n+    platform_dirent64 *dirent;\n+    while ((dirent = platform_readdir(directory_handle_)) != NULL &&\n+           IsMetaEntry(dirent)) {}\n+    if (dirent == NULL) {\n+      return false;\n     }\n \n     platform_stat64 info;\n-    retval = platform_lstat(dirent->d_name, &info);\n-    if (retval != 0) {\n-      closedir(dirp);\n+    if (platform_lstat(dirent->d_name, &info) != 0) {\n       return false;\n     }\n \n-    if (S_ISDIR(info.st_mode)) {\n-      // Recursion\n-      retval = chdir(dirent->d_name);\n-      if (retval != 0) {\n-        closedir(dirp);\n-        return false;\n-      }\n-      retval = ClearWorkingDir();\n-      if (!retval) {\n-        closedir(dirp);\n-        return false;\n-      }\n-      retval = chdir(\"..\");\n-      if (retval != 0) {\n-        closedir(dirp);\n-        return false;\n-      }\n-      retval = rmdir(dirent->d_name);\n-      if (retval != 0) {\n-        closedir(dirp);\n-        return false;\n-      }\n+    entry->is_directory = S_ISDIR(info.st_mode);\n+    entry->name         = dirent->d_name;\n+    return true;\n+  }\n+\n+ protected:\n+  string GetCurrentWorkingDirectory() {\n+    char path[PATH_MAX];\n+    const char* cwd = getcwd(path, PATH_MAX);\n+    assert(cwd == path);\n+    return string(cwd);\n+  }\n+\n+  void ChangeDirectory(const string &path) {\n+    const int retval = chdir(path.c_str());\n+    assert(retval == 0);\n+  }\n+\n+  bool IsMetaEntry(const platform_dirent64 *dirent) {","path":"cvmfs/cvmfs_suid_helper.cc","position":null,"original_position":103,"commit_id":"f29e4b2f83cde42921a42709cbb8c02d150db98e","original_commit_id":"74daa2ac146259b021620012bca51b738984957f","user":{"login":"reneme","id":1562139,"avatar_url":"https://avatars.githubusercontent.com/u/1562139?v=3","gravatar_id":"","url":"https://api.github.com/users/reneme","html_url":"https://github.com/reneme","followers_url":"https://api.github.com/users/reneme/followers","following_url":"https://api.github.com/users/reneme/following{/other_user}","gists_url":"https://api.github.com/users/reneme/gists{/gist_id}","starred_url":"https://api.github.com/users/reneme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneme/subscriptions","organizations_url":"https://api.github.com/users/reneme/orgs","repos_url":"https://api.github.com/users/reneme/repos","events_url":"https://api.github.com/users/reneme/events{/privacy}","received_events_url":"https://api.github.com/users/reneme/received_events","type":"User","site_admin":false},"body":"[aye](https://github.com/cvmfs/cvmfs/pull/1541/commits/3d4610df4aa7da545f05f2eecfdfee1c5dd61d1a).","created_at":"2016-04-06T13:28:50Z","updated_at":"2016-04-06T13:28:50Z","html_url":"https://github.com/cvmfs/cvmfs/pull/1541#discussion_r58703908","pull_request_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541","_links":{"self":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments/58703908"},"html":{"href":"https://github.com/cvmfs/cvmfs/pull/1541#discussion_r58703908"},"pull_request":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541"}}},"pull_request":{"url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541","id":63075411,"html_url":"https://github.com/cvmfs/cvmfs/pull/1541","diff_url":"https://github.com/cvmfs/cvmfs/pull/1541.diff","patch_url":"https://github.com/cvmfs/cvmfs/pull/1541.patch","issue_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/1541","number":1541,"state":"open","locked":false,"title":"Feature: Asynchronous Cleanup of Scratch Directory","user":{"login":"reneme","id":1562139,"avatar_url":"https://avatars.githubusercontent.com/u/1562139?v=3","gravatar_id":"","url":"https://api.github.com/users/reneme","html_url":"https://github.com/reneme","followers_url":"https://api.github.com/users/reneme/followers","following_url":"https://api.github.com/users/reneme/following{/other_user}","gists_url":"https://api.github.com/users/reneme/gists{/gist_id}","starred_url":"https://api.github.com/users/reneme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneme/subscriptions","organizations_url":"https://api.github.com/users/reneme/orgs","repos_url":"https://api.github.com/users/reneme/repos","events_url":"https://api.github.com/users/reneme/events{/privacy}","received_events_url":"https://api.github.com/users/reneme/received_events","type":"User","site_admin":false},"body":"This Pull Request is requesting for comments!\r\n\r\nAfter `cvmfs_server publish`-ing a large change set it might take a significant time to clean-out the scratch directory (i.e. `/var/spool/cvmfs/<fqrn>/scratch`). This allows to run this clean-up asynchronously to allow for quicker publishing round-trips. Setting `CVMFS_ASYNC_SCRATCH_CLEANUP=false` disables this and reverts back to the legacy behaviour.\r\n\r\nThe general idea of this workflow is:\r\n\r\n0. create `current` and `wastebin` inside `/var/spool/cvmfs/<fqrn>/scratch`\r\n1. publish as usual (using `.../scratch/current` as union fs scratch directory)\r\n2. umount `/cvmfs/<fqrn>` and `/var/spool/cvmfs/<fqrn>/rdonly`\r\n3. move `.../scratch/current` into `.../wastebin/waste.XXXXXX/current`\r\n4. create a fresh `.../scratch/current`\r\n5. spawn daemon process asynchronously deleting everything in `.../wastebin`\r\n6. mount `/var/spool/cvmfs/<fqrn>/rdonly` and `/cvmfs/<fqrn>`\r\n\r\nNote that there might be multiple concurrent `cvmfs_suid_helper clear_scratch_async` but they should not step on each other's feet. Subject to review: Is this actually true?\r\n\r\nTheoretically back-to-back transactions should become quicker but this effect might be mitigated due to the background process stressing the file system with the recursive delete.\r\n\r\nFurthermore this requires a repository migration step *2.2.x --> 2.3.0* to be developed.","created_at":"2016-03-16T14:41:50Z","updated_at":"2016-04-06T13:28:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"567c9be89587092c2a125eac569339fac720cb2c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541/commits","review_comments_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541/comments","review_comment_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/1541/comments","statuses_url":"https://api.github.com/repos/cvmfs/cvmfs/statuses/f29e4b2f83cde42921a42709cbb8c02d150db98e","head":{"label":"reneme:feature-async_clean","ref":"feature-async_clean","sha":"f29e4b2f83cde42921a42709cbb8c02d150db98e","user":{"login":"reneme","id":1562139,"avatar_url":"https://avatars.githubusercontent.com/u/1562139?v=3","gravatar_id":"","url":"https://api.github.com/users/reneme","html_url":"https://github.com/reneme","followers_url":"https://api.github.com/users/reneme/followers","following_url":"https://api.github.com/users/reneme/following{/other_user}","gists_url":"https://api.github.com/users/reneme/gists{/gist_id}","starred_url":"https://api.github.com/users/reneme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneme/subscriptions","organizations_url":"https://api.github.com/users/reneme/orgs","repos_url":"https://api.github.com/users/reneme/repos","events_url":"https://api.github.com/users/reneme/events{/privacy}","received_events_url":"https://api.github.com/users/reneme/received_events","type":"User","site_admin":false},"repo":{"id":6594761,"name":"cvmfs","full_name":"reneme/cvmfs","owner":{"login":"reneme","id":1562139,"avatar_url":"https://avatars.githubusercontent.com/u/1562139?v=3","gravatar_id":"","url":"https://api.github.com/users/reneme","html_url":"https://github.com/reneme","followers_url":"https://api.github.com/users/reneme/followers","following_url":"https://api.github.com/users/reneme/following{/other_user}","gists_url":"https://api.github.com/users/reneme/gists{/gist_id}","starred_url":"https://api.github.com/users/reneme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneme/subscriptions","organizations_url":"https://api.github.com/users/reneme/orgs","repos_url":"https://api.github.com/users/reneme/repos","events_url":"https://api.github.com/users/reneme/events{/privacy}","received_events_url":"https://api.github.com/users/reneme/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/reneme/cvmfs","description":"The CernVM File System","fork":true,"url":"https://api.github.com/repos/reneme/cvmfs","forks_url":"https://api.github.com/repos/reneme/cvmfs/forks","keys_url":"https://api.github.com/repos/reneme/cvmfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reneme/cvmfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reneme/cvmfs/teams","hooks_url":"https://api.github.com/repos/reneme/cvmfs/hooks","issue_events_url":"https://api.github.com/repos/reneme/cvmfs/issues/events{/number}","events_url":"https://api.github.com/repos/reneme/cvmfs/events","assignees_url":"https://api.github.com/repos/reneme/cvmfs/assignees{/user}","branches_url":"https://api.github.com/repos/reneme/cvmfs/branches{/branch}","tags_url":"https://api.github.com/repos/reneme/cvmfs/tags","blobs_url":"https://api.github.com/repos/reneme/cvmfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reneme/cvmfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reneme/cvmfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/reneme/cvmfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reneme/cvmfs/statuses/{sha}","languages_url":"https://api.github.com/repos/reneme/cvmfs/languages","stargazers_url":"https://api.github.com/repos/reneme/cvmfs/stargazers","contributors_url":"https://api.github.com/repos/reneme/cvmfs/contributors","subscribers_url":"https://api.github.com/repos/reneme/cvmfs/subscribers","subscription_url":"https://api.github.com/repos/reneme/cvmfs/subscription","commits_url":"https://api.github.com/repos/reneme/cvmfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/reneme/cvmfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/reneme/cvmfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/reneme/cvmfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/reneme/cvmfs/contents/{+path}","compare_url":"https://api.github.com/repos/reneme/cvmfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reneme/cvmfs/merges","archive_url":"https://api.github.com/repos/reneme/cvmfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reneme/cvmfs/downloads","issues_url":"https://api.github.com/repos/reneme/cvmfs/issues{/number}","pulls_url":"https://api.github.com/repos/reneme/cvmfs/pulls{/number}","milestones_url":"https://api.github.com/repos/reneme/cvmfs/milestones{/number}","notifications_url":"https://api.github.com/repos/reneme/cvmfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reneme/cvmfs/labels{/name}","releases_url":"https://api.github.com/repos/reneme/cvmfs/releases{/id}","deployments_url":"https://api.github.com/repos/reneme/cvmfs/deployments","created_at":"2012-11-08T10:30:55Z","updated_at":"2015-05-17T23:18:28Z","pushed_at":"2016-04-06T13:28:06Z","git_url":"git://github.com/reneme/cvmfs.git","ssh_url":"git@github.com:reneme/cvmfs.git","clone_url":"https://github.com/reneme/cvmfs.git","svn_url":"https://github.com/reneme/cvmfs","homepage":"http://cernvm.cern.ch/portal/filesystem","size":95503,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"cvmfs:devel","ref":"devel","sha":"fba9d36f71ffc5f44567c863a1fd24c3ec16f462","user":{"login":"cvmfs","id":1560859,"avatar_url":"https://avatars.githubusercontent.com/u/1560859?v=3","gravatar_id":"","url":"https://api.github.com/users/cvmfs","html_url":"https://github.com/cvmfs","followers_url":"https://api.github.com/users/cvmfs/followers","following_url":"https://api.github.com/users/cvmfs/following{/other_user}","gists_url":"https://api.github.com/users/cvmfs/gists{/gist_id}","starred_url":"https://api.github.com/users/cvmfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvmfs/subscriptions","organizations_url":"https://api.github.com/users/cvmfs/orgs","repos_url":"https://api.github.com/users/cvmfs/repos","events_url":"https://api.github.com/users/cvmfs/events{/privacy}","received_events_url":"https://api.github.com/users/cvmfs/received_events","type":"Organization","site_admin":false},"repo":{"id":3784908,"name":"cvmfs","full_name":"cvmfs/cvmfs","owner":{"login":"cvmfs","id":1560859,"avatar_url":"https://avatars.githubusercontent.com/u/1560859?v=3","gravatar_id":"","url":"https://api.github.com/users/cvmfs","html_url":"https://github.com/cvmfs","followers_url":"https://api.github.com/users/cvmfs/followers","following_url":"https://api.github.com/users/cvmfs/following{/other_user}","gists_url":"https://api.github.com/users/cvmfs/gists{/gist_id}","starred_url":"https://api.github.com/users/cvmfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cvmfs/subscriptions","organizations_url":"https://api.github.com/users/cvmfs/orgs","repos_url":"https://api.github.com/users/cvmfs/repos","events_url":"https://api.github.com/users/cvmfs/events{/privacy}","received_events_url":"https://api.github.com/users/cvmfs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cvmfs/cvmfs","description":"The CernVM File System","fork":false,"url":"https://api.github.com/repos/cvmfs/cvmfs","forks_url":"https://api.github.com/repos/cvmfs/cvmfs/forks","keys_url":"https://api.github.com/repos/cvmfs/cvmfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cvmfs/cvmfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cvmfs/cvmfs/teams","hooks_url":"https://api.github.com/repos/cvmfs/cvmfs/hooks","issue_events_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/events{/number}","events_url":"https://api.github.com/repos/cvmfs/cvmfs/events","assignees_url":"https://api.github.com/repos/cvmfs/cvmfs/assignees{/user}","branches_url":"https://api.github.com/repos/cvmfs/cvmfs/branches{/branch}","tags_url":"https://api.github.com/repos/cvmfs/cvmfs/tags","blobs_url":"https://api.github.com/repos/cvmfs/cvmfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cvmfs/cvmfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cvmfs/cvmfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/cvmfs/cvmfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cvmfs/cvmfs/statuses/{sha}","languages_url":"https://api.github.com/repos/cvmfs/cvmfs/languages","stargazers_url":"https://api.github.com/repos/cvmfs/cvmfs/stargazers","contributors_url":"https://api.github.com/repos/cvmfs/cvmfs/contributors","subscribers_url":"https://api.github.com/repos/cvmfs/cvmfs/subscribers","subscription_url":"https://api.github.com/repos/cvmfs/cvmfs/subscription","commits_url":"https://api.github.com/repos/cvmfs/cvmfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/cvmfs/cvmfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/cvmfs/cvmfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/cvmfs/cvmfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/cvmfs/cvmfs/contents/{+path}","compare_url":"https://api.github.com/repos/cvmfs/cvmfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cvmfs/cvmfs/merges","archive_url":"https://api.github.com/repos/cvmfs/cvmfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cvmfs/cvmfs/downloads","issues_url":"https://api.github.com/repos/cvmfs/cvmfs/issues{/number}","pulls_url":"https://api.github.com/repos/cvmfs/cvmfs/pulls{/number}","milestones_url":"https://api.github.com/repos/cvmfs/cvmfs/milestones{/number}","notifications_url":"https://api.github.com/repos/cvmfs/cvmfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cvmfs/cvmfs/labels{/name}","releases_url":"https://api.github.com/repos/cvmfs/cvmfs/releases{/id}","deployments_url":"https://api.github.com/repos/cvmfs/cvmfs/deployments","created_at":"2012-03-21T09:10:41Z","updated_at":"2016-03-19T08:45:07Z","pushed_at":"2016-04-06T13:28:06Z","git_url":"git://github.com/cvmfs/cvmfs.git","ssh_url":"git@github.com:cvmfs/cvmfs.git","clone_url":"https://github.com/cvmfs/cvmfs.git","svn_url":"https://github.com/cvmfs/cvmfs","homepage":"http://cernvm.cern.ch/portal/filesystem","size":104563,"stargazers_count":41,"watchers_count":41,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":12,"forks":45,"open_issues":12,"watchers":41,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541"},"html":{"href":"https://github.com/cvmfs/cvmfs/pull/1541"},"issue":{"href":"https://api.github.com/repos/cvmfs/cvmfs/issues/1541"},"comments":{"href":"https://api.github.com/repos/cvmfs/cvmfs/issues/1541/comments"},"review_comments":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541/comments"},"review_comment":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cvmfs/cvmfs/pulls/1541/commits"},"statuses":{"href":"https://api.github.com/repos/cvmfs/cvmfs/statuses/f29e4b2f83cde42921a42709cbb8c02d150db98e"}}}}