Ignore:
Timestamp:
Feb 9, 2013, 4:05:03 AM (8 years ago)
Author:
jordan
Message:

(trunk) first draft of changing the FreeSpace? API to behave as https://trac.transmissionbt.com/ticket/4076#comment:25 -- libT, rpc, qt, and gtk implementations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r13975 r13991  
    5757
    5858#include <assert.h>
     59#include <errno.h>
    5960#include <stdio.h>
    6061#include <stdlib.h>
     
    8182 #include <xfs/xqm.h>
    8283#endif
     84
     85#include <event2/util.h> /* evutil_ascii_strcasecmp () */
    8386
    8487#include "transmission.h"
     
    733736
    734737#ifndef WIN32
    735 static char *
     738static const char *
    736739getdev (const char * path)
    737740{
     
    784787}
    785788
    786 static char *
     789static const char *
    787790getfstype (const char * device)
    788791{
     
    834837}
    835838
    836 static char *
     839static const char *
    837840getblkdev (const char * path)
    838841{
    839842  char * c;
    840843  char * dir;
    841   char * device;
     844  const char * device;
    842845
    843846  dir = tr_strdup(path);
     
    861864
    862865static int64_t
    863 getquota (char * device)
     866getquota (const char * device)
    864867{
    865868  struct dqblk dq;
     
    961964
    962965static int64_t
    963 tr_getQuotaFreeSpace (const char * path, char * device, char * fstype)
    964 {
    965   int64_t ret=-1;
     966tr_getQuotaFreeSpace (const struct tr_device_info * info)
     967{
     968  int64_t ret = -1;
    966969
    967970#ifndef WIN32
    968971
    969   /* save device for future use */
    970   if (!*device)
    971     {
    972       char * d = getblkdev (path);
    973       if (d == NULL)
    974         return ret;
    975       tr_strlcpy (device, d, PATH_MAX + 1);
    976     }
    977 
    978   /* save FS type for future use */
    979   if (!*fstype)
    980     {
    981       char * fs = getfstype (device);
    982       if (fs != NULL)
    983         tr_strlcpy (fstype, fs, PATH_MAX + 1);
    984     }
    985 
    986   if (strcasecmp(fstype, "xfs") == 0)
     972  if (info->fstype && !evutil_ascii_strcasecmp(info->fstype, "xfs"))
    987973    {
    988974#ifdef HAVE_XQM
    989       ret = getxfsquota(device);
     975      ret = getxfsquota (info->device);
    990976#endif
    991977    }
    992978  else
    993979    {
    994       ret = getquota(device);
    995     }
    996 
     980      ret = getquota (info->device);
     981    }
    997982#endif /* WIN32 */
     983
    998984  return ret;
    999985}
     
    10221008}
    10231009
     1010struct tr_device_info *
     1011tr_device_info_create (const char * path)
     1012{
     1013  struct tr_device_info * info;
     1014
     1015  info = tr_new0 (struct tr_device_info, 1);
     1016  info->path = tr_strdup (path);
     1017  info->device = tr_strdup (getblkdev (path));
     1018  info->fstype = tr_strdup (getfstype (path));
     1019
     1020  return info;
     1021}
     1022
     1023void
     1024tr_device_info_free (struct tr_device_info * info)
     1025{
     1026  if (info != NULL)
     1027    {
     1028      tr_free (info->fstype);
     1029      tr_free (info->device);
     1030      tr_free (info->path);
     1031      tr_free (info);
     1032    }
     1033}
     1034
    10241035int64_t
    1025 tr_getFreeSpace (const char * path, char * device, char * fstype)
    1026 {
    1027   int64_t i = tr_getQuotaFreeSpace (path, device, fstype);
    1028 
    1029   if (i < 0)
    1030     i = tr_getDiskFreeSpace (path);
    1031 
    1032   return i;
     1036tr_device_info_get_free_space (const struct tr_device_info * info)
     1037{
     1038  int64_t free_space;
     1039
     1040  if ((info == NULL) || (info->path == NULL))
     1041    {
     1042      errno = EINVAL;
     1043      free_space = -1;
     1044    }
     1045  else
     1046    {
     1047      free_space = tr_getQuotaFreeSpace (info);
     1048
     1049      if (free_space < 0)
     1050        free_space = tr_getDiskFreeSpace (info->path);
     1051    }
     1052
     1053  return free_space;
    10331054}
    10341055
Note: See TracChangeset for help on using the changeset viewer.