Skip to content

Commit e8f7adc

Browse files
committed
Replace csync_vio_file_stat_t with csync_file_stat_t
Also move csync_normalize_etag to common/utility since we don't need the char* function anymore. Remove the single space file_stat->remotePerm codepath since this won't be used in csync anymore since 8de3bda. Issue #1817
1 parent 704ca36 commit e8f7adc

32 files changed

+361
-809
lines changed

src/common/utility.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,26 @@ QString Utility::fileNameForGuiUse(const QString &fName)
380380
return fName;
381381
}
382382

383+
QByteArray Utility::normalizeEtag(QByteArray etag)
384+
{
385+
/* strip "XXXX-gzip" */
386+
if(etag.startsWith('"') && etag.endsWith("-gzip\"")) {
387+
etag.chop(6);
388+
etag.remove(0, 1);
389+
}
390+
/* strip trailing -gzip */
391+
if(etag.endsWith("-gzip")) {
392+
etag.chop(5);
393+
}
394+
/* strip normal quotes */
395+
if (etag.startsWith('"') && etag.endsWith('"')) {
396+
etag.chop(1);
397+
etag.remove(0, 1);
398+
}
399+
etag.squeeze();
400+
return etag;
401+
}
402+
383403
bool Utility::hasDarkSystray()
384404
{
385405
return hasDarkSystray_private();

src/common/utility.h

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ namespace Utility {
131131

132132
OCSYNC_EXPORT QString fileNameForGuiUse(const QString &fName);
133133

134+
OCSYNC_EXPORT QByteArray normalizeEtag(QByteArray etag);
135+
134136
/**
135137
* @brief timeAgoInWords - human readable time span
136138
*

src/csync/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ set(csync_SRCS
7777
csync_rename.cpp
7878

7979
vio/csync_vio.cpp
80-
vio/csync_vio_file_stat.cpp
8180
)
8281

8382
if (WIN32)

src/csync/csync.h

+5-89
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <stdint.h>
4040
#include <sys/types.h>
4141
#include <config_csync.h>
42+
#include <memory>
4243
#include <QByteArray>
4344

4445
enum csync_status_codes_e {
@@ -54,7 +55,6 @@ enum csync_status_codes_e {
5455
CSYNC_STATUS_TIMESKEW, /* OBSOLETE */
5556
CSYNC_STATUS_FILESYSTEM_UNKNOWN, /* UNUSED */
5657
CSYNC_STATUS_TREE_ERROR, /* csync trees could not be created */
57-
CSYNC_STATUS_MEMORY_ERROR, /* not enough memory problem */
5858
CSYNC_STATUS_PARAM_ERROR, /* parameter is zero where not expected */
5959
CSYNC_STATUS_UPDATE_ERROR, /* general update or discovery error */
6060
CSYNC_STATUS_RECONCILE_ERROR, /* general reconcile error */
@@ -150,82 +150,6 @@ enum csync_ftw_type_e {
150150
// currently specified at https://github.com/owncloud/core/issues/8322 are 9 to 10
151151
#define REMOTE_PERM_BUF_SIZE 15
152152

153-
typedef struct csync_vio_file_stat_s csync_vio_file_stat_t;
154-
155-
enum csync_vio_file_flags_e {
156-
CSYNC_VIO_FILE_FLAGS_NONE = 0,
157-
CSYNC_VIO_FILE_FLAGS_SYMLINK = 1 << 0,
158-
CSYNC_VIO_FILE_FLAGS_HIDDEN = 1 << 1
159-
};
160-
161-
enum csync_vio_file_type_e {
162-
CSYNC_VIO_FILE_TYPE_UNKNOWN,
163-
CSYNC_VIO_FILE_TYPE_REGULAR,
164-
CSYNC_VIO_FILE_TYPE_DIRECTORY,
165-
CSYNC_VIO_FILE_TYPE_FIFO,
166-
CSYNC_VIO_FILE_TYPE_SOCKET,
167-
CSYNC_VIO_FILE_TYPE_CHARACTER_DEVICE,
168-
CSYNC_VIO_FILE_TYPE_BLOCK_DEVICE,
169-
CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK
170-
};
171-
172-
enum csync_vio_file_stat_fields_e {
173-
CSYNC_VIO_FILE_STAT_FIELDS_NONE = 0,
174-
CSYNC_VIO_FILE_STAT_FIELDS_TYPE = 1 << 0,
175-
CSYNC_VIO_FILE_STAT_FIELDS_MODE = 1 << 1, // local POSIX mode
176-
CSYNC_VIO_FILE_STAT_FIELDS_FLAGS = 1 << 2,
177-
// CSYNC_VIO_FILE_STAT_FIELDS_DEVICE = 1 << 3,
178-
CSYNC_VIO_FILE_STAT_FIELDS_INODE = 1 << 4,
179-
// CSYNC_VIO_FILE_STAT_FIELDS_LINK_COUNT = 1 << 5,
180-
CSYNC_VIO_FILE_STAT_FIELDS_SIZE = 1 << 6,
181-
// CSYNC_VIO_FILE_STAT_FIELDS_BLOCK_COUNT = 1 << 7, /* will be removed */
182-
// CSYNC_VIO_FILE_STAT_FIELDS_BLOCK_SIZE = 1 << 8, /* will be removed */
183-
CSYNC_VIO_FILE_STAT_FIELDS_ATIME = 1 << 9,
184-
CSYNC_VIO_FILE_STAT_FIELDS_MTIME = 1 << 10,
185-
CSYNC_VIO_FILE_STAT_FIELDS_CTIME = 1 << 11,
186-
// CSYNC_VIO_FILE_STAT_FIELDS_SYMLINK_NAME = 1 << 12,
187-
// CSYNC_VIO_FILE_STAT_FIELDS_CHECKSUM = 1 << 13,
188-
// CSYNC_VIO_FILE_STAT_FIELDS_ACL = 1 << 14,
189-
// CSYNC_VIO_FILE_STAT_FIELDS_UID = 1 << 15,
190-
// CSYNC_VIO_FILE_STAT_FIELDS_GID = 1 << 16,
191-
CSYNC_VIO_FILE_STAT_FIELDS_ETAG = 1 << 17,
192-
CSYNC_VIO_FILE_STAT_FIELDS_FILE_ID = 1 << 18,
193-
CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADURL = 1 << 19,
194-
CSYNC_VIO_FILE_STAT_FIELDS_DIRECTDOWNLOADCOOKIES = 1 << 20,
195-
CSYNC_VIO_FILE_STAT_FIELDS_PERM = 1 << 21 // remote oC perm
196-
197-
};
198-
199-
200-
struct csync_vio_file_stat_s {
201-
char *name;
202-
char *etag; // FIXME: Should this be inlined like file_id and perm?
203-
char file_id[FILE_ID_BUF_SIZE+1];
204-
char *directDownloadUrl;
205-
char *directDownloadCookies;
206-
char remotePerm[REMOTE_PERM_BUF_SIZE+1];
207-
208-
time_t atime;
209-
time_t mtime;
210-
time_t ctime;
211-
int64_t size;
212-
213-
mode_t mode;
214-
215-
uint64_t inode;
216-
217-
int fields; // actually enum csync_vio_file_stat_fields_e fields;
218-
enum csync_vio_file_type_e type;
219-
220-
int flags;
221-
222-
char *original_name; // only set if locale conversion fails
223-
224-
// For remote file stats: the highest quality checksum the server provided
225-
// in the "SHA1:324315da2143" form.
226-
char *checksumHeader;
227-
};
228-
229153
typedef struct csync_file_stat_s csync_file_stat_t;
230154

231155
struct csync_file_stat_s {
@@ -236,6 +160,7 @@ struct csync_file_stat_s {
236160
enum csync_ftw_type_e type : 4;
237161
bool child_modified : 1;
238162
bool has_ignored_files : 1; /* specify that a directory, or child directory contains ignored files */
163+
bool is_hidden : 1; // Not saved in the DB, only used during discovery for local files.
239164

240165
QByteArray path;
241166
QByteArray rename_path;
@@ -244,6 +169,7 @@ struct csync_file_stat_s {
244169
QByteArray directDownloadUrl;
245170
QByteArray directDownloadCookies;
246171
QByteArray remotePerm;
172+
QByteArray original_path; // only set if locale conversion fails
247173

248174
// In the local tree, this can hold a checksum and its type if it is
249175
// computed during discovery for some reason.
@@ -263,21 +189,12 @@ struct csync_file_stat_s {
263189
, type(CSYNC_FTW_TYPE_SKIP)
264190
, child_modified(false)
265191
, has_ignored_files(false)
192+
, is_hidden(false)
266193
, error_status(CSYNC_STATUS_OK)
267194
, instruction(CSYNC_INSTRUCTION_NONE)
268195
{ }
269196
};
270197

271-
csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_file_stat_new(void);
272-
csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_file_stat_copy(csync_vio_file_stat_t *file_stat);
273-
274-
void OCSYNC_EXPORT csync_vio_file_stat_destroy(csync_vio_file_stat_t *fstat);
275-
276-
void OCSYNC_EXPORT csync_vio_file_stat_set_file_id( csync_vio_file_stat_t* dst, const char* src );
277-
278-
void OCSYNC_EXPORT csync_vio_set_file_id(char* dst, const char *src );
279-
280-
281198
/**
282199
* CSync File Traversal structure.
283200
*
@@ -338,7 +255,7 @@ typedef void (*csync_update_callback) (bool local,
338255
typedef void csync_vio_handle_t;
339256
typedef csync_vio_handle_t* (*csync_vio_opendir_hook) (const char *url,
340257
void *userdata);
341-
typedef csync_vio_file_stat_t* (*csync_vio_readdir_hook) (csync_vio_handle_t *dhhandle,
258+
typedef std::unique_ptr<csync_file_stat_t> (*csync_vio_readdir_hook) (csync_vio_handle_t *dhhandle,
342259
void *userdata);
343260
typedef void (*csync_vio_closedir_hook) (csync_vio_handle_t *dhhandle,
344261
void *userdata);
@@ -539,7 +456,6 @@ void OCSYNC_EXPORT csync_resume(CSYNC *ctx);
539456
*/
540457
int OCSYNC_EXPORT csync_abort_requested(CSYNC *ctx);
541458

542-
char OCSYNC_EXPORT *csync_normalize_etag(const char *);
543459
time_t OCSYNC_EXPORT oc_httpdate_parse( const char *date );
544460

545461
/**

src/csync/csync_exclude.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "c_lib.h"
3333
#include "c_private.h"
34+
#include "c_utf8.h"
3435

3536
#include "csync_private.h"
3637
#include "csync_exclude.h"

src/csync/csync_misc.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -170,37 +170,3 @@ CSYNC_STATUS csync_errno_to_status(int error, CSYNC_STATUS default_status)
170170

171171
return status;
172172
}
173-
174-
/* Remove possible quotes, and also the -gzip at the end
175-
* Remove "-gzip" at the end (cf. https://github.comowncloud/client/issues/1195)
176-
* The caller must take ownership of the resulting string.
177-
*/
178-
char *csync_normalize_etag(const char *etag)
179-
{
180-
int len = 0;
181-
char *buf = NULL;
182-
if (!etag)
183-
return NULL;
184-
185-
len = strlen(etag);
186-
/* strip "XXXX-gzip" */
187-
if(len >= 7 && etag[0] == '"' && c_streq(etag + len - 6, "-gzip\"")) {
188-
etag++;
189-
len -= 7;
190-
}
191-
/* strip leading -gzip */
192-
if(len >= 5 && c_streq(etag + len - 5, "-gzip")) {
193-
len -= 5;
194-
}
195-
/* strip normal quotes */
196-
if (etag[0] == '"' && etag[len-1] == '"') {
197-
etag++;
198-
len -= 2;
199-
}
200-
201-
buf = (char*)c_malloc( len+1 );
202-
strncpy( buf, etag, len );
203-
buf[len] = '\0';
204-
return buf;
205-
}
206-

src/csync/csync_statedb.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include "c_string.h"
4444
#include "c_jhash.h"
45+
#include "c_utf8.h"
4546
#include "csync_time.h"
4647

4748
#define CSYNC_LOG_CATEGORY_NAME "csync.statedb"

0 commit comments

Comments
 (0)