[Pkg-owncloud-commits] [owncloud-client] 61/332: CSync & statedb: Parse 'perm' from server

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 70ff9283817e15d52fb931166badf3f413e89895
Author: Markus Goetz <markus at woboq.com>
Date:   Fri Jun 6 15:24:17 2014 +0200

    CSync & statedb: Parse 'perm' from server
    
    ownCloud 6 sends this.
---
 csync/src/csync.c                    |  1 +
 csync/src/csync.h                    |  1 +
 csync/src/csync_owncloud_private.h   |  4 +++-
 csync/src/csync_owncloud_util.c      | 34 +++++++++++-----------------------
 csync/src/csync_private.h            |  1 +
 csync/src/csync_statedb.c            |  9 ++++++++-
 csync/src/csync_update.c             |  4 +++-
 csync/src/vio/csync_vio_file_stat.h  | 12 +++++++++---
 csync/src/vio/csync_vio_local.c      |  2 +-
 src/mirall/syncengine.cpp            |  3 +++
 src/mirall/syncfileitem.h            |  2 ++
 src/mirall/syncjournaldb.cpp         | 30 +++++++++++++++++-------------
 src/mirall/syncjournalfilerecord.cpp |  2 +-
 src/mirall/syncjournalfilerecord.h   |  7 +++----
 14 files changed, 64 insertions(+), 48 deletions(-)

diff --git a/csync/src/csync.c b/csync/src/csync.c
index 1ecf725..072b076 100644
--- a/csync/src/csync.c
+++ b/csync/src/csync.c
@@ -403,6 +403,7 @@ static int _csync_treewalk_visitor(void *obj, void *data) {
       trav.rename_path  = cur->destpath;
       trav.etag         = cur->etag;
       trav.file_id      = cur->file_id;
+      trav.remotePerm = cur->remotePerm;
       trav.directDownloadUrl = cur->directDownloadUrl;
       trav.directDownloadCookies = cur->directDownloadCookies;
       trav.inode        = cur->inode;
diff --git a/csync/src/csync.h b/csync/src/csync.h
index 46410a2..607e0a0 100644
--- a/csync/src/csync.h
+++ b/csync/src/csync.h
@@ -175,6 +175,7 @@ struct csync_tree_walk_file_s {
     const char *rename_path;
     const char *etag;
     const char *file_id;
+    const char *remotePerm;
     char *directDownloadUrl;
     char *directDownloadCookies;
     struct {
diff --git a/csync/src/csync_owncloud_private.h b/csync/src/csync_owncloud_private.h
index 67eedc4..ffe84c7 100644
--- a/csync/src/csync_owncloud_private.h
+++ b/csync/src/csync_owncloud_private.h
@@ -127,6 +127,7 @@ static const ne_propname ls_props[] = {
     { "http://owncloud.org/ns", "id"},
     { "http://owncloud.org/ns", "dDU"},
     { "http://owncloud.org/ns", "dDC"},
+    { "http://owncloud.org/ns", "perm"},
     { NULL, NULL }
 };
 
@@ -146,6 +147,8 @@ typedef struct resource {
     // without going through the ownCloud instance.
     char *directDownloadUrl;
     char *directDownloadCookies;
+    // See https://github.com/owncloud/core/issues/8322
+    char remotePerm[REMOTE_PERM_BUF_SIZE+1];
 
     struct resource    *next;
 } resource;
@@ -186,7 +189,6 @@ time_t oc_httpdate_parse( const char *date );
 
 char *_cleanPath( const char* uri );
 
-int _stat_perms( int type );
 void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop_result_set *set);
 
 void resourceToFileStat( csync_vio_file_stat_t *lfs, struct resource *res );
diff --git a/csync/src/csync_owncloud_util.c b/csync/src/csync_owncloud_util.c
index 7840cd0..628dc44 100644
--- a/csync/src/csync_owncloud_util.c
+++ b/csync/src/csync_owncloud_util.c
@@ -298,10 +298,6 @@ void resourceToFileStat(csync_vio_file_stat_t *lfs, struct resource *res )
         DEBUG_WEBDAV("ERROR: Unknown resource type %d", res->type);
     }
 
-    // FIXME Those are defaults, we'll have to use the real ownCloud WebDAV permissions soon
-    lfs->mode   = _stat_perms( lfs->type );
-    lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
-
     lfs->mtime = res->modtime;
     lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
     lfs->size  = res->size;
@@ -321,26 +317,10 @@ void resourceToFileStat(csync_vio_file_stat_t *lfs, struct resource *res )
         lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES;
         lfs->directDownloadCookies = c_strdup(res->directDownloadCookies);
     }
-}
-
-/* WebDAV does not deliver permissions. Set a default here. */
-int _stat_perms( int type ) {
-    int ret = 0;
-
-    if( type == CSYNC_VIO_FILE_TYPE_DIRECTORY ) {
-        /* DEBUG_WEBDAV("Setting mode in stat (dir)"); */
-        /* directory permissions */
-        ret = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR /* directory, rwx for user */
-                | S_IRGRP | S_IXGRP                       /* rx for group */
-                | S_IROTH | S_IXOTH;                      /* rx for others */
-    } else {
-        /* regualar file permissions */
-        /* DEBUG_WEBDAV("Setting mode in stat (file)"); */
-        ret = S_IFREG | S_IRUSR | S_IWUSR /* regular file, user read & write */
-                | S_IRGRP                         /* group read perm */
-                | S_IROTH;                        /* others read perm */
+    if (strlen(res->remotePerm) > 0) {
+        lfs->fields = CSYNC_VIO_FILE_STAT_FIELDS_PERM;
+        strncpy(lfs->remotePerm, res->remotePerm, sizeof(lfs->remotePerm));
     }
-    return ret;
 }
 
 void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop_result_set *set)
@@ -350,6 +330,7 @@ void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop
     const char *directDownloadCookies = NULL;
     const char *resourcetype = NULL;
     const char *etag = NULL;
+    const char *perm = NULL;
 
     modtime      = ne_propset_value( set, &ls_props[0] );
     clength      = ne_propset_value( set, &ls_props[1] );
@@ -358,6 +339,7 @@ void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop
     file_id      = ne_propset_value( set, &ls_props[4] );
     directDownloadUrl = ne_propset_value( set, &ls_props[5] );
     directDownloadCookies = ne_propset_value( set, &ls_props[6] );
+    perm = ne_propset_value( set, &ls_props[7] );
 
     if( resourcetype && strncmp( resourcetype, "<DAV:collection>", 16 ) == 0) {
         newres->type = resr_collection;
@@ -391,6 +373,9 @@ void fill_webdav_properties_into_resource(struct resource* newres, const ne_prop
     if (directDownloadCookies) {
         newres->directDownloadCookies = c_strdup(directDownloadCookies);
     }
+    if (perm && strlen(perm) < sizeof(newres->remotePerm)) {
+        strncpy(newres->remotePerm, perm, sizeof(newres->remotePerm));
+    }
 }
 
 struct resource* resource_dup(struct resource* o) {
@@ -411,6 +396,9 @@ struct resource* resource_dup(struct resource* o) {
     if (o->directDownloadCookies) {
         r->directDownloadCookies = c_strdup(o->directDownloadCookies);
     }
+    if (o->remotePerm) {
+        strncpy(r->remotePerm, o->remotePerm, sizeof(r->remotePerm));
+    }
     r->next = o->next;
     csync_vio_set_file_id(r->file_id, o->file_id);
 
diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h
index cc6e650..cadc651 100644
--- a/csync/src/csync_private.h
+++ b/csync/src/csync_private.h
@@ -167,6 +167,7 @@ struct csync_file_stat_s {
   char file_id[FILE_ID_BUF_SIZE+1];  /* the ownCloud file id is fixed width of 21 byte. */
   char *directDownloadUrl;
   char *directDownloadCookies;
+  char remotePerm[REMOTE_PERM_BUF_SIZE+1];
 
   CSYNC_STATUS error_status;
 
diff --git a/csync/src/csync_statedb.c b/csync/src/csync_statedb.c
index fee0b73..4c254cf 100644
--- a/csync/src/csync_statedb.c
+++ b/csync/src/csync_statedb.c
@@ -311,6 +311,13 @@ static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3
             if(column_count > 10 && sqlite3_column_text(stmt,10)) {
                 csync_vio_set_file_id((*st)->file_id, (char*) sqlite3_column_text(stmt, 10));
             }
+            if(column_count > 11 && sqlite3_column_text(stmt,11)) {
+                strncpy((*st)->remotePerm,
+                        (char*) sqlite3_column_text(stmt, 11),
+                        sizeof((*st)->remotePerm));
+            }
+            CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "%s %s",sqlite3_column_text(stmt, 10),sqlite3_column_text(stmt, 11) );
+
         }
     }
     return rc;
@@ -450,7 +457,7 @@ char *csync_statedb_get_etag( CSYNC *ctx, uint64_t jHash ) {
     return ret;
 }
 
-#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid FROM metadata WHERE path LIKE(?)"
+#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM metadata WHERE path LIKE(?)"
 
 int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
     int rc;
diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index c451a4e..d9c88e2 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -377,7 +377,9 @@ out:
       SAFE_FREE(st->directDownloadCookies);
       st->directDownloadCookies = c_strdup(fs->directDownloadCookies);
   }
-
+  if (fs->fields & CSYNC_VIO_FILE_STAT_FIELDS_PERM) {
+      strncpy(st->remotePerm, fs->remotePerm, sizeof(st->remotePerm));
+  }
 
 fastout:  /* target if the file information is read from database into st */
   st->phash = h;
diff --git a/csync/src/vio/csync_vio_file_stat.h b/csync/src/vio/csync_vio_file_stat.h
index d1d9058..21c4eaf 100644
--- a/csync/src/vio/csync_vio_file_stat.h
+++ b/csync/src/vio/csync_vio_file_stat.h
@@ -34,6 +34,9 @@
 
 #define FILE_ID_BUF_SIZE 21
 
+// currently specified at https://github.com/owncloud/core/issues/8322 are 9 to 10
+#define REMOTE_PERM_BUF_SIZE 15
+
 typedef struct csync_vio_file_stat_s csync_vio_file_stat_t;
 
 enum csync_vio_file_flags_e {
@@ -56,7 +59,7 @@ enum csync_vio_file_type_e {
 enum csync_vio_file_stat_fields_e {
   CSYNC_VIO_FILE_STAT_FIELDS_NONE = 0,
   CSYNC_VIO_FILE_STAT_FIELDS_TYPE = 1 << 0,
-  CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS = 1 << 1,
+  CSYNC_VIO_FILE_STAT_FIELDS_MODE = 1 << 1, // local POSIX mode
   CSYNC_VIO_FILE_STAT_FIELDS_FLAGS = 1 << 2,
   CSYNC_VIO_FILE_STAT_FIELDS_DEVICE = 1 << 3,
   CSYNC_VIO_FILE_STAT_FIELDS_INODE = 1 << 4,
@@ -75,16 +78,19 @@ enum csync_vio_file_stat_fields_e {
   CSYNC_VIO_FILE_STAT_FIELDS_ETAG = 1 << 17,
   CSYNC_VIO_FILE_STAT_FIELDS_FILE_ID = 1 << 18,
   CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADURL = 1 << 19,
-  CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES = 1 << 20
+  CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES = 1 << 20,
+  CSYNC_VIO_FILE_STAT_FIELDS_PERM = 1 << 21 // remote oC perm
+
 };
 
 
 struct csync_vio_file_stat_s {
   char *name;
-  char *etag;
+  char *etag; // FIXME: Should this be inlined like file_id and perm?
   char file_id[FILE_ID_BUF_SIZE+1];
   char *directDownloadUrl;
   char *directDownloadCookies;
+  char remotePerm[REMOTE_PERM_BUF_SIZE+1];
 
   time_t atime;
   time_t mtime;
diff --git a/csync/src/vio/csync_vio_local.c b/csync/src/vio/csync_vio_local.c
index fdea8ae..791e099 100644
--- a/csync/src/vio/csync_vio_local.c
+++ b/csync/src/vio/csync_vio_local.c
@@ -315,7 +315,7 @@ int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
   buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
 
   buf->mode = sb.st_mode;
-  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
+  buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MODE;
 
   if (buf->type == CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK) {
     /* FIXME: handle symlink */
diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp
index 75adc3e..d16f4f7 100644
--- a/src/mirall/syncengine.cpp
+++ b/src/mirall/syncengine.cpp
@@ -269,6 +269,9 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
     if (file->directDownloadCookies) {
         item._directDownloadCookies = QString::fromUtf8( file->directDownloadCookies );
     }
+    if (file->remotePerm) {
+        item._remotePerm = QByteArray(file->remotePerm);
+    }
 
     // record the seen files to be able to clean the journal later
     _seenFiles[item._file] = QString();
diff --git a/src/mirall/syncfileitem.h b/src/mirall/syncfileitem.h
index e4d2cd4..b869a3d 100644
--- a/src/mirall/syncfileitem.h
+++ b/src/mirall/syncfileitem.h
@@ -86,6 +86,7 @@ public:
     quint64              _inode;
     bool                 _should_update_etag;
     QByteArray           _fileId;
+    QByteArray           _remotePerm;
     QString              _directDownloadUrl;
     QString              _directDownloadCookies;
     bool                 _blacklistedInDb;
@@ -107,6 +108,7 @@ public:
         time_t      _other_modtime;
         QByteArray  _other_etag;
         QByteArray  _other_fileId;
+        QByteArray  _other_remotePerm;
         enum csync_instructions_e _other_instruction;
     } log;
 };
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp
index c8e1014..41ff6b7 100644
--- a/src/mirall/syncjournaldb.cpp
+++ b/src/mirall/syncjournaldb.cpp
@@ -146,6 +146,8 @@ bool SyncJournalDb::checkConnect()
                          "modtime INTEGER(8),"
                          "type INTEGER,"
                          "md5 VARCHAR(32)," /* This is the etag.  Called md5 for compatibility */
+                        // updateDatabaseStructure() will add a fileid column
+                        // updateDatabaseStructure() will add a remotePerm column
                          "PRIMARY KEY(phash)"
                          ");");
 
@@ -227,13 +229,13 @@ bool SyncJournalDb::checkConnect()
     bool rc = updateDatabaseStructure();
     if( rc ) {
         _getFileRecordQuery.reset(new QSqlQuery(_db));
-        _getFileRecordQuery->prepare("SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid FROM "
+        _getFileRecordQuery->prepare("SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM "
                                      "metadata WHERE phash=:ph" );
 
         _setFileRecordQuery.reset(new QSqlQuery(_db) );
         _setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata "
-                                     "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid) "
-                                     "VALUES ( ? , ?, ? , ? , ? , ? , ?,  ? , ? , ?, ? )" );
+                                     "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm) "
+                                     "VALUES ( ? , ?, ? , ? , ? , ? , ?,  ? , ? , ?, ?, ? )" );
 
         _getDownloadInfoQuery.reset(new QSqlQuery(_db) );
         _getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
@@ -318,6 +320,13 @@ bool SyncJournalDb::updateDatabaseStructure()
 
         commitInternal("update database structure");
     }
+    if( columns.indexOf(QLatin1String("remotePerm")) == -1 ) {
+
+        QSqlQuery query(_db);
+        query.prepare("ALTER TABLE metadata ADD COLUMN remotePerm VARCHAR(128);");
+        re = query.exec();
+        commitInternal("update database structure (remotePerm");
+    }
 
     return re;
 }
@@ -371,13 +380,12 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
         QByteArray arr = record._path.toUtf8();
         int plen = arr.length();
 
-        // _setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata "
-        //                            "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid) "
-        //                            "VALUES ( ? , ?, ? , ? , ? , ? , ?,  ? , ? , ?, ? )" );
         QString etag( record._etag );
         if( etag.isEmpty() ) etag = "";
         QString fileId( record._fileId);
         if( fileId.isEmpty() ) fileId = "";
+        QString remotePerm (record._remotePerm);
+        if (remotePerm.isEmpty()) remotePerm = "";
 
         _setFileRecordQuery->bindValue(0, QString::number(phash));
         _setFileRecordQuery->bindValue(1, plen);
@@ -390,6 +398,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
         _setFileRecordQuery->bindValue(8, QString::number(record._type) );
         _setFileRecordQuery->bindValue(9, etag );
         _setFileRecordQuery->bindValue(10, fileId );
+        _setFileRecordQuery->bindValue(11, remotePerm );
 
         if( !_setFileRecordQuery->exec() ) {
             qWarning() << "Error SQL statement setFileRecord: " << _setFileRecordQuery->lastQuery() <<  " :"
@@ -400,7 +409,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
         qDebug() <<  _setFileRecordQuery->lastQuery() << phash << plen << record._path << record._inode
                  << record._mode
                  << QString::number(Utility::qDateTimeToTime_t(record._modtime)) << QString::number(record._type)
-                 << record._etag << record._fileId;
+                 << record._etag << record._fileId << record._remotePerm;
         _setFileRecordQuery->finish();
 
         return true;
@@ -455,12 +464,6 @@ SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename )
     qlonglong phash = getPHash( filename );
     SyncJournalFileRecord rec;
 
-    /*
-    CREATE TABLE "metadata"(phash INTEGER(8),pathlen INTEGER,path VARCHAR(4096),inode INTEGER,uid INTEGER,gid INTEGER,mode INTEGER,modtime INTEGER(8),type INTEGER,md5 VARCHAR(32),PRIMARY KEY(phash));
-    CREATE INDEX metadata_inode ON metadata(inode);
-    CREATE INDEX metadata_phash ON metadata(phash);
-    */
-
     if( checkConnect() ) {
         _getFileRecordQuery->bindValue(":ph", QString::number(phash));
 
@@ -481,6 +484,7 @@ SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename )
             rec._type    = _getFileRecordQuery->value(6).toInt(&ok);
             rec._etag    = _getFileRecordQuery->value(7).toString();
             rec._fileId  = _getFileRecordQuery->value(8).toString();
+            rec._remotePerm = _getFileRecordQuery->value(9).toByteArray();
 
             _getFileRecordQuery->finish();
         } else {
diff --git a/src/mirall/syncjournalfilerecord.cpp b/src/mirall/syncjournalfilerecord.cpp
index 5c091ca..f29ec88 100644
--- a/src/mirall/syncjournalfilerecord.cpp
+++ b/src/mirall/syncjournalfilerecord.cpp
@@ -33,7 +33,7 @@ SyncJournalFileRecord::SyncJournalFileRecord()
 
 SyncJournalFileRecord::SyncJournalFileRecord(const SyncFileItem &item, const QString &localFileName)
     : _path(item._file), _modtime(Utility::qDateTimeFromTime_t(item._modtime)),
-      _type(item._type), _etag(item._etag), _fileId(item._fileId),
+      _type(item._type), _etag(item._etag), _fileId(item._fileId), _remotePerm(item._remotePerm),
       _mode(0)
 {
     // use the "old" inode coming with the item for the case where the
diff --git a/src/mirall/syncjournalfilerecord.h b/src/mirall/syncjournalfilerecord.h
index 351e99c..8ac7513 100644
--- a/src/mirall/syncjournalfilerecord.h
+++ b/src/mirall/syncjournalfilerecord.h
@@ -31,14 +31,13 @@ public:
         return !_path.isEmpty();
     }
 
-    // query("SELECT path, inode, uid, gid, mode, modtime, type, md5 FROM metadata WHERE phash=:phash");
-
     QString   _path;
     quint64   _inode;
     QDateTime _modtime;
     int       _type;
-    QString   _etag;
-    QString   _fileId;
+    QString   _etag; // FIXME Why not QByteArray?
+    QString   _fileId; // FIXME Why not QByteArray?
+    QByteArray _remotePerm;
     int       _mode;
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list