]> sourceware.org Git - systemtap.git/commitdiff
The http client code now asks the server to delete the build info.
authorDavid Smith <dsmith@redhat.com>
Thu, 5 Apr 2018 15:55:31 +0000 (10:55 -0500)
committerDavid Smith <dsmith@redhat.com>
Thu, 5 Apr 2018 15:55:31 +0000 (10:55 -0500)
* client-http.cxx (http_client_backend::delete_op): Send a delete request
  to the server.
  (http_client_backend::unpack_response): After downloading everything,
  call delete_op().
* httpd/api.cxx (individual_build_rh::DELETE): New function.

client-http.cxx
httpd/api.cxx

index 13664a925cf35204e7f45b80e934fa32a889ad3c..c2349f3d0ccb617e3260a8d115959b5fab2bc582 100644 (file)
@@ -71,6 +71,7 @@ public:
   void get_kernel_buildid (void);
   long get_response_code (void);
   static int trace (CURL *, curl_infotype type, unsigned char *data, size_t size, void *);
+  bool delete_op (const std::string & url);
 
 private:
   size_t get_header (void *ptr, size_t size, size_t nitems);
@@ -744,6 +745,35 @@ http_client::add_module (std::string module)
 }
 
 
+// Ask the server to delete a URL.
+
+bool
+http_client::delete_op (const std::string & url)
+{
+  if (curl)
+    curl_easy_reset (curl);
+  curl = curl_easy_init ();
+  curl_global_init (CURL_GLOBAL_ALL);
+  if (s.verbose > 2)
+    {
+      curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L);
+      curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, trace);
+    }
+  curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+  curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); //Prevent "longjmp causes uninitialized stack frame" bug
+  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
+
+  CURLcode res = curl_easy_perform (curl);
+  if (res != CURLE_OK)
+    {
+      clog << "curl_easy_perform() failed: " << curl_easy_strerror (res)
+          << endl;
+      return false;
+    }
+  return true;
+}
+
+
 http_client_backend::http_client_backend (systemtap_session &s)
   : client_backend(s), files_seen(false)
 {
@@ -1059,6 +1089,9 @@ http_client_backend::unpack_response ()
       clog << "Couldn't find 'stdout' in JSON results data" << endl;
       return 1;
     }
+
+  // Tell the server to delete this build (and any associated result).
+  http->delete_op (build_uri);
   return 0;
 }
 
index 63fb852cc047bd165b4dc50d245136717de29b26..e4400825b6808a1c70f5356bef3f4d398e84a473 100644 (file)
@@ -480,6 +480,7 @@ public:
     individual_build_rh(string n) : request_handler(n) {}
 
     response GET(const request &req);
+    response DELETE(const request &req);
 };
 
 response individual_build_rh::GET(const request &req)
@@ -512,6 +513,37 @@ response individual_build_rh::GET(const request &req)
     return rsp;
 }
 
+response individual_build_rh::DELETE(const request &req)
+{
+    // matches[0] is the entire string '/builds/XXXX'. matches[1] is
+    // just the buildid 'XXXX'.
+    string buildid = req.matches[1];
+    build_info *b = NULL;
+    {
+       // Use a lock_guard to ensure the mutex gets released even if an
+       // exception is thrown.
+       lock_guard<mutex> lock(builds_mutex);
+       for (auto it = build_infos.begin(); it != build_infos.end(); it++) {
+           if (buildid == (*it)->get_uuid_str()) {
+               b = *it;
+               build_infos.erase(it);
+               break;
+           }
+       }
+    }
+
+    if (b == NULL) {
+       server_error(_F("Couldn't find build '%s'", buildid.c_str()));
+       return get_404_response();
+    }
+
+    // At this point we've found a matching build. Delete it.
+    delete b;
+    response rsp(300);
+    rsp.content = "";
+    return rsp;
+}
+
 class individual_result_rh : public request_handler
 {
 public:
This page took 0.033431 seconds and 5 git commands to generate.