view mercurial/cffi/osutil.py @ 30775:513d68a90398

repair: implement requirements checking for upgrades This commit introduces functionality for upgrading a repository in place. The first part that's implemented is testing for upgrade "compatibility." This is done by examining repository requirements. There are 5 functions returning sets of requirements that control upgrading. Why so many functions? Mainly to support extensions. Functions are easier to monkeypatch than module variables. Astute readers will see that we don't support "manifestv2" and "treemanifest" requirements in the upgrade mechanism. I don't have a great answer for why other than this is a complex set of patches and I don't want to deal with the complexity of these experimental features just yet. We can teach the upgrade mechanism about them later, once the basic upgrade mechanism is in place. This commit also introduces the "upgraderepo" function. This will be our main routine for performing an in-place upgrade. Currently, it just implements requirements checking. The structure of some code in this function may look a bit weird (e.g. the inline function that is only called once). But this will make sense after future commits.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 18 Dec 2016 16:16:54 -0800
parents 9cc438bf7d9a
children 857876ebaed4
line wrap: on
line source

from __future__ import absolute_import

import cffi

ffi = cffi.FFI()
ffi.set_source("_osutil_cffi", """
#include <sys/attr.h>
#include <sys/vnode.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>

typedef struct val_attrs {
    uint32_t          length;
    attribute_set_t   returned;
    attrreference_t   name_info;
    fsobj_type_t      obj_type;
    struct timespec   mtime;
    uint32_t          accessmask;
    off_t             datalength;
} __attribute__((aligned(4), packed)) val_attrs_t;
""", include_dirs=['mercurial'])
ffi.cdef('''

typedef uint32_t attrgroup_t;

typedef struct attrlist {
    uint16_t     bitmapcount; /* number of attr. bit sets in list */
    uint16_t   reserved;    /* (to maintain 4-byte alignment) */
    attrgroup_t commonattr;  /* common attribute group */
    attrgroup_t volattr;     /* volume attribute group */
    attrgroup_t dirattr;     /* directory attribute group */
    attrgroup_t fileattr;    /* file attribute group */
    attrgroup_t forkattr;    /* fork attribute group */
    ...;
};

typedef struct attribute_set {
    ...;
} attribute_set_t;

typedef struct attrreference {
    int attr_dataoffset;
    int attr_length;
    ...;
} attrreference_t;

typedef int ... off_t;

typedef struct val_attrs {
    uint32_t          length;
    attribute_set_t   returned;
    attrreference_t   name_info;
    uint32_t          obj_type;
    struct timespec   mtime;
    uint32_t          accessmask;
    off_t             datalength;
    ...;
} val_attrs_t;

/* the exact layout of the above struct will be figured out during build time */

typedef int ... time_t;

typedef struct timespec {
    time_t tv_sec;
    ...;
};

int getattrlist(const char* path, struct attrlist * attrList, void * attrBuf,
                size_t attrBufSize, unsigned int options);

int getattrlistbulk(int dirfd, struct attrlist * attrList, void * attrBuf,
                    size_t attrBufSize, uint64_t options);

#define ATTR_BIT_MAP_COUNT ...
#define ATTR_CMN_NAME ...
#define ATTR_CMN_OBJTYPE ...
#define ATTR_CMN_MODTIME ...
#define ATTR_CMN_ACCESSMASK ...
#define ATTR_CMN_ERROR ...
#define ATTR_CMN_RETURNED_ATTRS ...
#define ATTR_FILE_DATALENGTH ...

#define VREG ...
#define VDIR ...
#define VLNK ...
#define VBLK ...
#define VCHR ...
#define VFIFO ...
#define VSOCK ...

#define S_IFMT ...

int open(const char *path, int oflag, int perm);
int close(int);

#define O_RDONLY ...
''')

if __name__ == '__main__':
    ffi.compile()