Skip to content

Commit

Permalink
portable visual studio 2019 (#2378)
Browse files Browse the repository at this point in the history
* portable visual studio 2019

* Need alignment and fix compile warning

* Define related headers in common.h

* del reference config.h

* Add files generated by vala

* Def reference config.h for windows

* Support vs build

Co-authored-by: sun <[email protected]>
  • Loading branch information
feiniks and sun20121818 authored Nov 18, 2020
1 parent 88da64b commit cb877e0
Show file tree
Hide file tree
Showing 34 changed files with 5,281 additions and 57 deletions.
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ debian/*.substvars
lib/*.tmp
lib/dir.c
lib/dirent.c
lib/seafile-object.h
lib/task.c
lib/webaccess.c
lib/branch.c
lib/commit.c
lib/crypt.c
lib/repo.c
lib/copy-task.c
app/seafile
app/seafserv-tool
Expand Down Expand Up @@ -125,3 +122,12 @@ server/gc/seaf-migrate
/test-driver
*.dmp
/symbols

# visual studio
Debug
msi/custom/x64
msi/ext.wxi
msi/shell.wxs
seafile.vcxproj.user
x64
msi/custom/seafile_custom.vcxproj.user
5 changes: 4 additions & 1 deletion common/block-backend-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

#include <sys/stat.h>
#include <fcntl.h>
#ifndef WIN32
#include <dirent.h>
#endif

#include "block-backend.h"
#include "obj-store.h"
Expand Down Expand Up @@ -190,6 +192,7 @@ block_backend_fs_block_exists (BlockBackend *bend,
char block_path[SEAF_PATH_MAX];

get_block_path (bend, block_sha1, block_path, store_id, version);

if (g_access (block_path, F_OK) == 0)
return TRUE;
else
Expand Down Expand Up @@ -336,7 +339,7 @@ block_backend_fs_copy (BlockBackend *bend,
}

#ifdef WIN32
if (!CreateHardLink (dst_path, src_path, NULL)) {
if (!CreateHardLinkA (dst_path, src_path, NULL)) {
seaf_warning ("Failed to link %s to %s: %lu.\n",
src_path, dst_path, GetLastError());
return -1;
Expand Down
6 changes: 4 additions & 2 deletions common/block-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

#include <stdio.h>
#include <errno.h>
#ifndef WIN32
#include <unistd.h>
#include <dirent.h>
#endif
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <dirent.h>
#include <glib/gstdio.h>

#include "block-backend.h"
Expand Down Expand Up @@ -98,7 +100,7 @@ void
seaf_block_manager_block_handle_free (SeafBlockManager *mgr,
BlockHandle *handle)
{
return mgr->backend->block_handle_free (mgr->backend, handle);
mgr->backend->block_handle_free (mgr->backend, handle);
}

int
Expand Down
2 changes: 2 additions & 0 deletions common/cdc/cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "log.h"

#ifndef WIN32
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
Expand Down
31 changes: 18 additions & 13 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@
#include <config.h>
#endif

#ifndef WIN32
#include <unistd.h>
#include <utime.h>
#endif
#include <stdlib.h>
#include <stdint.h> /* uint32_t */
#include <sys/types.h> /* size_t */
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <utime.h>

#include <glib.h>
#include <glib/gstdio.h>

#ifdef WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp

#if !defined S_ISDIR
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif

#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif

#define F_OK 0
#endif

#define EMPTY_SHA1 "0000000000000000000000000000000000000000"

#define CURRENT_ENC_VERSION 3
Expand All @@ -39,16 +56,4 @@

#define SEAF_PATH_MAX 4096

#ifndef ccnet_warning
#define ccnet_warning(fmt, ...) g_warning("%s(%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif

#ifndef ccnet_error
#define ccnet_error(fmt, ...) g_error("%s(%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif

#ifndef ccnet_message
#define ccnet_message(fmt, ...) g_message("%s(%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#endif

#endif
32 changes: 32 additions & 0 deletions common/fs-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <sys/stat.h>
#include <fcntl.h>
#ifndef WIN32
#include <dirent.h>
#endif

#ifndef WIN32
#include <arpa/inet.h>
Expand Down Expand Up @@ -33,23 +35,53 @@ struct _SeafFSManagerPriv {
GHashTable *bl_cache;
};

#ifdef WIN32
__pragma(pack(push, 1))
typedef struct SeafileOndisk {
guint32 type;
guint64 file_size;
unsigned char block_ids[0];
} SeafileOndisk;
__pragma(pack(pop))
#else
typedef struct SeafileOndisk {
guint32 type;
guint64 file_size;
unsigned char block_ids[0];
} __attribute__((__packed__)) SeafileOndisk;
#endif

#ifdef WIN32
__pragma(pack(push, 1))
typedef struct DirentOndisk {
guint32 mode;
char id[40];
guint32 name_len;
char name[0];
} DirentOndisk;
__pragma(pack(pop))
#else
typedef struct DirentOndisk {
guint32 mode;
char id[40];
guint32 name_len;
char name[0];
} __attribute__((__packed__)) DirentOndisk;
#endif

#ifdef WIN32
__pragma(pack(push, 1))
typedef struct SeafdirOndisk {
guint32 type;
char dirents[0];
} SeafdirOndisk;
__pragma(pack(pop))
#else
typedef struct SeafdirOndisk {
guint32 type;
char dirents[0];
} __attribute__((__packed__)) SeafdirOndisk;
#endif

#ifndef SEAFILE_SERVER
uint32_t
Expand Down
80 changes: 73 additions & 7 deletions common/index/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#include "common.h"

#ifndef WIN32
#include <unistd.h>
#include <sys/param.h>
#include <dirent.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand All @@ -15,10 +20,7 @@
#ifndef __APPLE__
#include <limits.h>
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/time.h>
#include <time.h>

#include "utils.h"
Expand Down Expand Up @@ -117,6 +119,23 @@ struct cache_time {
* We save the fields in big-endian order to allow using the
* index file over NFS transparently.
*/
#ifdef WIN32
__pragma(pack(push, 1))
struct ondisk_cache_entry {
struct cache_time ctime;
struct cache_time mtime;
unsigned int dev;
unsigned int ino;
unsigned int mode;
unsigned int uid;
unsigned int gid;
uint64_t size;
unsigned char sha1[20];
unsigned short flags;
char name[0]; /* more */
};
__pragma(pack(pop))
#else
struct ondisk_cache_entry {
struct cache_time ctime;
struct cache_time mtime;
Expand All @@ -129,13 +148,16 @@ struct ondisk_cache_entry {
unsigned char sha1[20];
unsigned short flags;
char name[0]; /* more */
} __attribute__ ((packed));
} __attribute__((__packed__));
#endif

struct cache_time64 {
guint64 sec;
guint64 nsec;
};

#ifdef WIN32
__pragma(pack(push, 1))
struct ondisk_cache_entry2 {
struct cache_time64 ctime;
struct cache_time64 mtime;
Expand All @@ -148,13 +170,31 @@ struct ondisk_cache_entry2 {
unsigned char sha1[20];
unsigned short flags;
char name[0]; /* more */
} __attribute__ ((packed));
};
__pragma(pack(pop))
#else
struct ondisk_cache_entry2 {
struct cache_time64 ctime;
struct cache_time64 mtime;
unsigned int dev;
unsigned int ino;
unsigned int mode;
unsigned int uid;
unsigned int gid;
uint64_t size;
unsigned char sha1[20];
unsigned short flags;
char name[0]; /* more */
} __attribute__((__packed__));
#endif

/*
* This struct is used when CE_EXTENDED bit is 1
* The struct must match ondisk_cache_entry exactly from
* ctime till flags
*/
#ifdef WIN32
__pragma(pack(push, 1))
struct ondisk_cache_entry_extended {
struct cache_time ctime;
struct cache_time mtime;
Expand All @@ -168,14 +208,40 @@ struct ondisk_cache_entry_extended {
unsigned short flags;
unsigned short flags2;
char name[0]; /* more */
} __attribute__ ((packed));
};
__pragma(pack(pop))
#else
struct ondisk_cache_entry_extended {
struct cache_time ctime;
struct cache_time mtime;
unsigned int dev;
unsigned int ino;
unsigned int mode;
unsigned int uid;
unsigned int gid;
uint64_t size;
unsigned char sha1[20];
unsigned short flags;
unsigned short flags2;
char name[0]; /* more */
} __attribute__((__packed__));
#endif

#define CACHE_EXT_MODIFIER 1

#ifdef WIN32
__pragma(pack(push, 1))
struct cache_ext_hdr {
unsigned int ext_name;
unsigned int ext_size;
} __attribute__ ((packed));
};
__pragma(pack(pop))
#else
struct cache_ext_hdr {
unsigned int ext_name;
unsigned int ext_size;
} __attribute__((__packed__));
#endif

struct cache_entry {
struct cache_time64 ce_ctime;
Expand Down
8 changes: 8 additions & 0 deletions common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
#define SEAFILE_DOMAIN g_quark_from_string("seafile")

#ifndef seaf_warning
#ifndef WIN32
#define seaf_warning(fmt, ...) g_warning("%s(%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define seaf_warning(...) g_warning(__VA_ARGS__)
#endif
#endif

#ifndef seaf_message
#ifndef WIN32
#define seaf_message(fmt, ...) g_message("%s(%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define seaf_message(...) g_message(__VA_ARGS__)
#endif
#endif


Expand Down
2 changes: 1 addition & 1 deletion common/obj-backend-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ obj_backend_fs_copy (ObjBackend *bend,
}

#ifdef WIN32
if (!CreateHardLink (dst_path, src_path, NULL)) {
if (!CreateHardLinkA (dst_path, src_path, NULL)) {
seaf_warning ("Failed to link %s to %s: %lu.\n",
src_path, dst_path, GetLastError());
return -1;
Expand Down
2 changes: 1 addition & 1 deletion common/obj-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ seaf_obj_store_delete_obj (struct SeafObjStore *obj_store,
!obj_id || !is_object_id_valid(obj_id))
return;

return bend->delete (bend, repo_id, version, obj_id);
bend->delete (bend, repo_id, version, obj_id);
}

int
Expand Down
2 changes: 2 additions & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <ctype.h>

#include <sys/stat.h>
#ifndef WIN32
#include <dirent.h>
#endif
#include "utils.h"

#include "seafile-session.h"
Expand Down
Loading

0 comments on commit cb877e0

Please sign in to comment.