]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/SVNRepository.cxx
SGPath: fix creating paths with permission checker.
[simgear.git] / simgear / io / SVNRepository.cxx
index b8768eab3878373a26ddbc3802f6694288d779c8..39114b1f172d93de878cfa39251bbd0569f583a6 100644 (file)
@@ -54,7 +54,7 @@ public:
     SVNRepoPrivate(SVNRepository* parent) : 
         p(parent), 
         isUpdating(false),
-        status(SVNRepository::NO_ERROR)
+        status(SVNRepository::SVN_NO_ERROR)
     { ; }
     
     SVNRepository* p; // link back to outer
@@ -73,7 +73,8 @@ public:
     
     void updateFailed(HTTP::Request* req, SVNRepository::ResultCode err)
     {
-        SG_LOG(SG_IO, SG_WARN, "SVN: failed to update from:" << req->url());
+        SG_LOG(SG_IO, SG_WARN, "SVN: failed to update from:" << req->url()
+            << "\n(repository:" << p->baseUrl() << ")");
         isUpdating = false;
         status = err;
     }
@@ -119,40 +120,9 @@ namespace { // anonmouse
         Request(repo->baseUrl, "PROPFIND"),
         _repo(repo)
       {
-      }
-  
-      virtual string_list requestHeaders() const
-      {
-        string_list r;
-        r.push_back("Depth");
-        return r;
-      }
-  
-      virtual string header(const string& name) const
-      {
-          if (name == "Depth") {
-              return "0";
-          }
-          
-          return string();
-      }
-  
-      virtual string requestBodyType() const
-      {
-          return "application/xml; charset=\"utf-8\"";
-      }
-  
-      virtual int requestBodyLength() const
-      {
-        return strlen(PROPFIND_REQUEST_BODY);
-      }
-  
-      virtual int getBodyData(char* buf, int count) const
-      {
-        int bodyLen = strlen(PROPFIND_REQUEST_BODY);
-        assert(count >= bodyLen);
-        memcpy(buf, PROPFIND_REQUEST_BODY, bodyLen);
-        return bodyLen;
+        requestHeader("Depth") = "0";
+        setBodyData( PROPFIND_REQUEST_BODY,
+                     "application/xml; charset=\"utf-8\"" );
       }
 
     protected:
@@ -161,19 +131,24 @@ namespace { // anonmouse
         if (responseCode() == 207) {
             // fine
         } else if (responseCode() == 404) {
-            _repo->propFindFailed(this, SVNRepository::ERROR_NOT_FOUND);
+            _repo->propFindFailed(this, SVNRepository::SVN_ERROR_NOT_FOUND);
         } else {
             SG_LOG(SG_IO, SG_WARN, "request for:" << url() << 
                 " return code " << responseCode());
-            _repo->propFindFailed(this, SVNRepository::ERROR_SOCKET);
+            _repo->propFindFailed(this, SVNRepository::SVN_ERROR_SOCKET);
+            _repo = NULL;
         }
       }
   
-      virtual void responseComplete()
+      virtual void onDone()
       {
         if (responseCode() == 207) {
           _davStatus.finishParse();
-          _repo->propFindComplete(this, (DAVCollection*) _davStatus.resource());
+          if (_davStatus.isValid()) {
+              _repo->propFindComplete(this, (DAVCollection*) _davStatus.resource());
+          } else {
+              _repo->propFindFailed(this, SVNRepository::SVN_ERROR_SOCKET);
+          }
         }
       }
   
@@ -184,69 +159,58 @@ namespace { // anonmouse
         }
         _davStatus.parseXML(s, n);
       }
+        
+        virtual void onFail()
+        {
+            HTTP::Request::onFail();
+                       if (_repo) {
+                               _repo->propFindFailed(this, SVNRepository::SVN_ERROR_SOCKET);
+                               _repo = NULL;
+                       }
+        }
+        
     private:
       SVNRepoPrivate* _repo;
       DAVMultiStatus _davStatus;
     };
 
-class UpdateReportRequest : public HTTP::Request
+class UpdateReportRequest:
+  public HTTP::Request
 {
 public:
   UpdateReportRequest(SVNRepoPrivate* repo, 
       const std::string& aVersionName,
       bool startEmpty) :
     HTTP::Request("", "REPORT"),
-    _requestSent(0),
     _parser(repo->p),
     _repo(repo),
     _failed(false)
   {       
     setUrl(repo->vccUrl);
-
-    _request =
+    std::string request =
     "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
     "<S:update-report send-all=\"true\" xmlns:S=\"svn:\">\n"
     "<S:src-path>" + repo->baseUrl + "</S:src-path>\n"
-    "<S:depth>unknown</S:depth>\n";
-
-    _request += "<S:entry rev=\"" + aVersionName + "\" depth=\"infinity\" start-empty=\"true\"/>\n";
-     
-    if (!startEmpty) {
-        string_list entries;
-        _repo->rootCollection->mergeUpdateReportDetails(0, entries);
-        BOOST_FOREACH(string e, entries) {
-            _request += e + "\n";
-        }
-    }
-
-    _request += "</S:update-report>";   
-  }
+    "<S:depth>unknown</S:depth>\n"
+    "<S:entry rev=\"" + aVersionName + "\" depth=\"infinity\" start-empty=\"true\"/>\n";
 
-  virtual string requestBodyType() const
-  {
-    return "application/xml; charset=\"utf-8\"";
-  }
+    if( !startEmpty )
+    {
+      string_list entries;
+      _repo->rootCollection->mergeUpdateReportDetails(0, entries);
+      BOOST_FOREACH(string e, entries)
+      {
+        request += e + "\n";
+      }
+    }
 
-  virtual int requestBodyLength() const
-  {
-    return _request.size();
-  }
+    request += "</S:update-report>";
 
-  virtual int getBodyData(char* buf, int count) const
-  {
-    int len = std::min(count, requestBodyLength() - _requestSent);
-    memcpy(buf, _request.c_str() + _requestSent, len);
-    _requestSent += len;
-    return len;
+    setBodyData(request, "application/xml; charset=\"utf-8\"");
   }
 
 protected:
-  virtual void responseHeadersComplete()
-  {
-
-  }
-
-  virtual void responseComplete()
+  virtual void onDone()
   {
       if (_failed) {
           return;
@@ -261,12 +225,12 @@ protected:
               _repo->svnUpdateDone();
           }
     } else if (responseCode() == 404) {
-        _repo->updateFailed(this, SVNRepository::ERROR_NOT_FOUND);
+        _repo->updateFailed(this, SVNRepository::SVN_ERROR_NOT_FOUND);
         _failed = true;
     } else {
         SG_LOG(SG_IO, SG_WARN, "SVN: request for:" << url() <<
-        " return code " << responseCode());
-        _repo->updateFailed(this, SVNRepository::ERROR_SOCKET);
+        " got HTTP status " << responseCode());
+        _repo->updateFailed(this, SVNRepository::SVN_ERROR_HTTP);
         _failed = true;
     }
   }
@@ -281,20 +245,24 @@ protected:
         return;
     }
     
-    //cout << "body data:" << string(s, n) << endl;
     SVNRepository::ResultCode err = _parser.parseXML(s, n);
     if (err) {
         _failed = true;
-        SG_LOG(SG_IO, SG_WARN, "SVN: request for:" << url() <<
-            " XML parse failed");
+        SG_LOG(SG_IO, SG_WARN, this << ": SVN: request for:" << url() << " failed:" << err);
         _repo->updateFailed(this, err);
+        _repo = NULL;
     }
   }
 
-
+    virtual void onFail()
+    {
+        HTTP::Request::onFail();
+        if (_repo) {
+            _repo->updateFailed(this, SVNRepository::SVN_ERROR_SOCKET);
+            _repo = NULL;
+        }
+    }
 private:
-  string _request;
-  mutable int _requestSent;
   SVNReportParser _parser;
   SVNRepoPrivate* _repo;
   bool _failed;
@@ -351,7 +319,7 @@ bool SVNRepository::isBare() const
 
 void SVNRepository::update()
 {  
-    _d->status = NO_ERROR;
+    _d->status = SVN_NO_ERROR;
     if (_d->targetRevision.empty() || _d->vccUrl.empty()) {        
         _d->isUpdating = true;        
         PropFindRequest* pfr = new PropFindRequest(_d.get());
@@ -373,7 +341,7 @@ void SVNRepository::update()
   
 bool SVNRepository::isDoingSync() const
 {
-    if (_d->status != NO_ERROR) {
+    if (_d->status != SVN_NO_ERROR) {
         return false;
     }
     
@@ -403,7 +371,7 @@ void SVNRepoPrivate::propFindComplete(HTTP::Request* req, DAVCollection* c)
   
 void SVNRepoPrivate::propFindFailed(HTTP::Request *req, SVNRepository::ResultCode err)
 {
-    if (err != SVNRepository::ERROR_NOT_FOUND) {
+    if (err != SVNRepository::SVN_ERROR_NOT_FOUND) {
         SG_LOG(SG_IO, SG_WARN, "PropFind failed for:" << req->url());
     }