Esempio n. 1
0
bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, tr_error** error)
{
    TR_ASSERT(path != NULL);
    TR_ASSERT(info != NULL);

    bool ret = false;
    wchar_t* wide_path = path_to_native_path(path);

    if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
    {
        HANDLE handle = INVALID_HANDLE_VALUE;

        if (wide_path != NULL)
        {
            handle = CreateFileW(wide_path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
        }

        if (handle != INVALID_HANDLE_VALUE)
        {
            tr_error* my_error = NULL;
            ret = tr_sys_file_get_info(handle, info, &my_error);

            if (!ret)
            {
                tr_error_propagate(error, &my_error);
            }

            CloseHandle(handle);
        }
        else
        {
            set_system_error(error, GetLastError());
        }
    }
    else
    {
        WIN32_FILE_ATTRIBUTE_DATA attributes;

        if (wide_path != NULL)
        {
            ret = GetFileAttributesExW(wide_path, GetFileExInfoStandard, &attributes);
        }

        if (ret)
        {
            stat_to_sys_path_info(attributes.dwFileAttributes, attributes.nFileSizeLow, attributes.nFileSizeHigh,
                &attributes.ftLastWriteTime, info);
        }
        else
        {
            set_system_error(error, GetLastError());
        }
    }

    tr_free(wide_path);

    return ret;
}
Esempio n. 2
0
bool tr_sys_file_get_info(tr_sys_file_t handle, tr_sys_path_info* info, tr_error** error)
{
    TR_ASSERT(handle != TR_BAD_SYS_FILE);
    TR_ASSERT(info != NULL);

    BY_HANDLE_FILE_INFORMATION attributes;
    bool ret = GetFileInformationByHandle(handle, &attributes);

    if (ret)
    {
        stat_to_sys_path_info(attributes.dwFileAttributes, attributes.nFileSizeLow, attributes.nFileSizeHigh,
            &attributes.ftLastWriteTime, info);
    }
    else
    {
        set_system_error(error, GetLastError());
    }

    return ret;
}
Esempio n. 3
0
static bool
get_file_info (HANDLE              handle,
               tr_sys_path_info  * info,
               tr_error         ** error)
{
  bool ret;
  BY_HANDLE_FILE_INFORMATION attributes;

  assert (handle != INVALID_HANDLE_VALUE);
  assert (info != NULL);

  ret = GetFileInformationByHandle (handle, &attributes);

  if (ret)
    stat_to_sys_path_info (attributes.dwFileAttributes, attributes.nFileSizeLow,
                           attributes.nFileSizeHigh, &attributes.ftLastWriteTime,
                           info);
  else
    set_system_error (error, GetLastError ());

  return ret;
}
Esempio n. 4
0
bool
tr_sys_path_get_info (const char        * path,
                      int                 flags,
                      tr_sys_path_info  * info,
                      tr_error         ** error)
{
  bool ret;
  struct stat sb;

  assert (path != NULL);
  assert (info != NULL);

  if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
    ret = stat (path, &sb) != -1;
  else
    ret = lstat (path, &sb) != -1;

  if (ret)
    stat_to_sys_path_info (&sb, info);
  else
    set_system_error (error, errno);

  return ret;
}