Exemplo n.º 1
0
/*
 * fs.lstat
 */
static int fs_lstat(lua_State* L) {
  FSR__SETUP
  const char *path = luaL_checkstring(L, 1);
  FSR__SET_OPT_CB(2, on_fs_callback)
  uv_fs_lstat(loop, req, path, cb);
  FSR__TEARDOWN
}
Exemplo n.º 2
0
Arquivo: sys.c Projeto: jakevdp/julia
DLLEXPORT int32_t jl_lstat(const char* path, char* statbuf)
{
  uv_fs_t req;
  int ret;

  ret = uv_fs_lstat(uv_default_loop(), &req, path, NULL);
  if (ret == 0)
    memcpy(statbuf, req.ptr, sizeof(struct stat));
  uv_fs_req_cleanup(&req);
  return ret;
}
Exemplo n.º 3
0
/// Get the file information for a given path without following links
///
/// @param path Path to the file.
/// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure.
bool os_get_file_info_link(const char *path, FileInfo *file_info)
{
  uv_fs_t request;
  int result = uv_fs_lstat(uv_default_loop(), &request, path, NULL);
  file_info->stat = request.statbuf;
  uv_fs_req_cleanup(&request);
  if (result == kLibuvSuccess) {
    return true;
  }
  return false;
}
Exemplo n.º 4
0
MVMint64 MVM_file_exists(MVMThreadContext *tc, MVMString *f, MVMint32 use_lstat) {
    uv_fs_t req;
    char * const a = MVM_string_utf8_encode_C_string(tc, f);
    const MVMint64 result = (use_lstat
                             ? uv_fs_lstat(tc->loop, &req, a, NULL)
                             :  uv_fs_stat(tc->loop, &req, a, NULL)
                            ) < 0 ? 0 : 1;

    MVM_free(a);

    return result;
}
Exemplo n.º 5
0
static uv_stat_t file_info(MVMThreadContext *tc, MVMString *filename, MVMint32 use_lstat) {
    char * const a = MVM_string_utf8_encode_C_string(tc, filename);
    uv_fs_t req;

    if ((use_lstat
            ? uv_fs_lstat(tc->loop, &req, a, NULL)
            :  uv_fs_stat(tc->loop, &req, a, NULL)
        ) < 0) {
        MVM_free(a);
        MVM_exception_throw_adhoc(tc, "Failed to stat file: %s", uv_strerror(req.result));
    }

    MVM_free(a);
    return req.statbuf;
}
Exemplo n.º 6
0
MVMint64 MVM_file_stat(MVMThreadContext *tc, MVMString *filename, MVMint64 status, MVMint32 use_lstat) {
    MVMint64 r = -1;

    switch (status) {

    case MVM_STAT_EXISTS:
        r = MVM_file_exists(tc, filename, use_lstat);
        break;

    case MVM_STAT_FILESIZE: {
        char * const a = MVM_string_utf8_encode_C_string(tc, filename);
        uv_fs_t req;

        if ((use_lstat
                ? uv_fs_lstat(tc->loop, &req, a, NULL)
                :  uv_fs_stat(tc->loop, &req, a, NULL)
            ) < 0) {
            MVM_free(a);
            MVM_exception_throw_adhoc(tc, "Failed to stat file: %s", uv_strerror(req.result));
        }
        MVM_free(a);

        r = req.statbuf.st_size;
        break;
    }

    case MVM_STAT_ISDIR:
        r = (file_info(tc, filename, use_lstat).st_mode & S_IFMT) == S_IFDIR;
        break;

    case MVM_STAT_ISREG:
        r = (file_info(tc, filename, use_lstat).st_mode & S_IFMT) == S_IFREG;
        break;

    case MVM_STAT_ISDEV: {
        const int mode = file_info(tc, filename, use_lstat).st_mode;
#ifdef _WIN32
        r = mode & S_IFMT == S_IFCHR;
#else
        r = (mode & S_IFMT) == S_IFCHR || (mode & S_IFMT) == S_IFBLK;
#endif
        break;
    }

    case MVM_STAT_CREATETIME:
        r = file_info(tc, filename, use_lstat).st_ctim.tv_sec;
        break;

    case MVM_STAT_ACCESSTIME:
        r = file_info(tc, filename, use_lstat).st_atim.tv_sec;
        break;

    case MVM_STAT_MODIFYTIME:
        r = file_info(tc, filename, use_lstat).st_mtim.tv_sec;
        break;

    case MVM_STAT_CHANGETIME:
        r = file_info(tc, filename, use_lstat).st_ctim.tv_sec;
        break;

    /*        case MVM_STAT_BACKUPTIME:         r = -1; break;  */

    case MVM_STAT_UID:
        r = file_info(tc, filename, use_lstat).st_uid;
        break;

    case MVM_STAT_GID:
        r = file_info(tc, filename, use_lstat).st_gid;
        break;

    case MVM_STAT_ISLNK:
        r = (file_info(tc, filename, 1).st_mode & S_IFMT) == S_IFLNK;
        break;

    case MVM_STAT_PLATFORM_DEV:
        r = file_info(tc, filename, use_lstat).st_dev;
        break;

    case MVM_STAT_PLATFORM_INODE:
        r = file_info(tc, filename, use_lstat).st_ino;
        break;

    case MVM_STAT_PLATFORM_MODE:
        r = file_info(tc, filename, use_lstat).st_mode;
        break;

    case MVM_STAT_PLATFORM_NLINKS:
        r = file_info(tc, filename, use_lstat).st_nlink;
        break;

    case MVM_STAT_PLATFORM_DEVTYPE:
        r = file_info(tc, filename, use_lstat).st_rdev;
        break;

    case MVM_STAT_PLATFORM_BLOCKSIZE:
        r = file_info(tc, filename, use_lstat).st_blksize;
        break;

    case MVM_STAT_PLATFORM_BLOCKS:
        r = file_info(tc, filename, use_lstat).st_blocks;
        break;

    default:
        break;
    }

    return r;
}