(trunk, libT) #3833 'freespace' argument for 'session-get' RPC method -- apply taem's 0003-Cache-download-dir-s-block-device-and-FS-type.patch to cache the download dir's block device and FS type
This commit is contained in:
parent
843d79d284
commit
4cbe6a64e1
|
@ -888,22 +888,33 @@ getxfsquota( char * device )
|
|||
#endif /* WIN32 */
|
||||
|
||||
static int64_t
|
||||
tr_getQuotaFreeSpace( const char * path )
|
||||
tr_getQuotaFreeSpace( const char * path, char * device, char * fstype )
|
||||
{
|
||||
int64_t ret=-1;
|
||||
#ifndef WIN32
|
||||
char *d, *device;
|
||||
char *fstype;
|
||||
char *d;
|
||||
char *fs;
|
||||
|
||||
if ((d = getblkdev(path)) == NULL)
|
||||
if (strlen(device) == 0)
|
||||
{
|
||||
return ret;
|
||||
if ((d = getblkdev(path)) == NULL)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
/* Save device for future use */
|
||||
tr_strlcpy(device, d, PATH_MAX + 1);
|
||||
}
|
||||
/* 'd' points to static area of memory, so copy it */
|
||||
device = tr_strdup(d);
|
||||
|
||||
fstype = getfstype(device);
|
||||
if (fstype != NULL && strcasecmp(fstype, "xfs") == 0)
|
||||
if (strlen(fstype) == 0)
|
||||
{
|
||||
if ((fs = getfstype(device)) != NULL)
|
||||
{
|
||||
/* Save FS type for future use */
|
||||
tr_strlcpy(fstype, fs, PATH_MAX + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(fstype, "xfs") == 0)
|
||||
{
|
||||
#ifdef HAVE_XQM
|
||||
ret = getxfsquota(device);
|
||||
|
@ -912,7 +923,6 @@ tr_getQuotaFreeSpace( const char * path )
|
|||
ret = getquota(device);
|
||||
}
|
||||
|
||||
tr_free(device);
|
||||
#endif /* WIN32 */
|
||||
return ret;
|
||||
}
|
||||
|
@ -935,9 +945,9 @@ tr_getDiskFreeSpace( const char * path )
|
|||
}
|
||||
|
||||
int64_t
|
||||
tr_getFreeSpace( const char * path )
|
||||
tr_getFreeSpace( const char * path, char * device, char * fstype )
|
||||
{
|
||||
int64_t i = tr_getQuotaFreeSpace( path );
|
||||
int64_t i = tr_getQuotaFreeSpace( path, device, fstype );
|
||||
if( i < 0 )
|
||||
i = tr_getDiskFreeSpace( path );
|
||||
return i;
|
||||
|
|
|
@ -44,7 +44,7 @@ const char * tr_getWebClientDir (const tr_session *);
|
|||
|
||||
/** If the disk quota is enabled and readable, this returns how much is available in the quota.
|
||||
Otherwise, it returns how much is available on the disk, or -1 on error. */
|
||||
int64_t tr_getFreeSpace (const char * path);
|
||||
int64_t tr_getFreeSpace (const char * path, char * device, char * fstype);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -590,6 +590,8 @@ tr_sessionInit (const char * tag,
|
|||
session->cache = tr_cacheNew (1024*1024*2);
|
||||
session->tag = tr_strdup (tag);
|
||||
session->magicNumber = SESSION_MAGIC_NUMBER;
|
||||
session->downloadDirBlkDev = tr_malloc (PATH_MAX + 1);
|
||||
session->downloadDirFsType = tr_malloc (PATH_MAX + 1);
|
||||
tr_bandwidthConstruct (&session->bandwidth, session, NULL);
|
||||
tr_peerIdInit (session->peer_id);
|
||||
tr_variantInitList (&session->removedTorrents, 0);
|
||||
|
@ -953,6 +955,8 @@ tr_sessionSetDownloadDir (tr_session * session, const char * dir)
|
|||
{
|
||||
tr_free (session->downloadDir);
|
||||
session->downloadDir = tr_strdup (dir);
|
||||
memset (session->downloadDirBlkDev, 0, sizeof(session->downloadDirBlkDev));
|
||||
memset (session->downloadDirFsType, 0, sizeof(session->downloadDirFsType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -969,7 +973,8 @@ tr_sessionGetDownloadDirFreeSpace (const tr_session * session)
|
|||
{
|
||||
assert (tr_isSession (session));
|
||||
|
||||
return tr_getFreeSpace (session->downloadDir);
|
||||
return tr_getFreeSpace (session->downloadDir, session->downloadDirBlkDev,
|
||||
session->downloadDirFsType);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -1879,6 +1884,8 @@ tr_sessionClose (tr_session * session)
|
|||
tr_free (session->resumeDir);
|
||||
tr_free (session->torrentDir);
|
||||
tr_free (session->downloadDir);
|
||||
tr_free (session->downloadDirBlkDev);
|
||||
tr_free (session->downloadDirFsType);
|
||||
tr_free (session->incompleteDir);
|
||||
tr_free (session->blocklist_url);
|
||||
tr_free (session->peer_congestion_algorithm);
|
||||
|
|
|
@ -182,6 +182,8 @@ struct tr_session
|
|||
char * tag;
|
||||
char * configDir;
|
||||
char * downloadDir;
|
||||
char * downloadDirBlkDev;
|
||||
char * downloadDirFsType;
|
||||
char * resumeDir;
|
||||
char * torrentDir;
|
||||
char * incompleteDir;
|
||||
|
|
Loading…
Reference in New Issue