mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(trunk, daemon) #3833 "'freespace' argument for 'session-get' RPC method" -- committing patch from taem, reardon, and rb07
This commit is contained in:
+3
-2
@@ -108,7 +108,7 @@ fi
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_TIME
|
||||
|
||||
AC_CHECK_FUNCS([iconv_open pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign])
|
||||
AC_CHECK_FUNCS([iconv_open pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs])
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
ACX_PTHREAD
|
||||
@@ -174,7 +174,8 @@ if test "x$want_kqueue" = "xyes" ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS([xfs/xfs.h])
|
||||
AC_CHECK_HEADERS([sys/statvfs.h \
|
||||
xfs/xfs.h])
|
||||
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1460,6 +1460,8 @@ printSession( tr_benc * top )
|
||||
printf( " Configuration directory: %s\n", str );
|
||||
if( tr_bencDictFindStr( args, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) )
|
||||
printf( " Download directory: %s\n", str );
|
||||
if( tr_bencDictFindInt( args, "download-dir-free-space", &i ) )
|
||||
printf( " Download directory free space: %s\n", strlsize( buf, i, sizeof buf ) );
|
||||
if( tr_bencDictFindInt( args, TR_PREFS_KEY_PEER_PORT, &i ) )
|
||||
printf( " Listenport: %" PRId64 "\n", i );
|
||||
if( tr_bencDictFindBool( args, TR_PREFS_KEY_PORT_FORWARDING, &boolVal ) )
|
||||
|
||||
+5
-2
@@ -417,6 +417,7 @@
|
||||
"cache-size-mb" | number | maximum size of the disk cache (MB)
|
||||
"config-dir" | string | location of transmission's configuration directory
|
||||
"download-dir" | string | default path to download torrents
|
||||
"download-dir-free-space" | number | number of free bytes available in download-dir, or -1 if it can't be calculated
|
||||
"dht-enabled" | boolean | true means allow dht in public torrents
|
||||
"encryption" | string | "required", "preferred", "tolerated"
|
||||
"idle-seeding-limit" | number | the default seed inactivity limit for torrents to use
|
||||
@@ -468,8 +469,8 @@
|
||||
|
||||
Method name: "session-set"
|
||||
Request arguments: one or more of 4.1's arguments, except: "blocklist-size",
|
||||
"config-dir", "rpc-version", "rpc-version-minimum",
|
||||
and "version"
|
||||
"config-dir", "download-dir-free-space", "rpc-version",
|
||||
"rpc-version-minimum", and "version"
|
||||
Response arguments: none
|
||||
|
||||
4.1.2. Accessors
|
||||
@@ -642,3 +643,5 @@
|
||||
------+---------+-----------+----------------+-------------------------------
|
||||
11 | 2.12 | yes | session-get | new arg "blocklist-url"
|
||||
| | yes | session-set | new arg "blocklist-url"
|
||||
------+---------+-----------+----------------+-------------------------------
|
||||
12 | 2.20 | yes | session-get | new arg "download-dir-free-space"
|
||||
|
||||
@@ -34,8 +34,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef SYS_DARWIN
|
||||
#define HAVE_SYS_STATVFS_H
|
||||
#define HAVE_STATVFS
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_STATVFS_H
|
||||
#include <sys/statvfs.h>
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
@@ -678,6 +686,27 @@ tr_getWebClientDir( const tr_session * session UNUSED )
|
||||
****
|
||||
***/
|
||||
|
||||
int64_t
|
||||
tr_getFreeSpace( const char * path )
|
||||
{
|
||||
#ifdef WIN32
|
||||
uint64_t freeBytesAvailable = 0;
|
||||
return GetDiskFreeSpaceEx( path, &freeBytesAvailable, NULL, NULL)
|
||||
? (int64_t)freeBytesAvailable
|
||||
: -1;
|
||||
#elif defined(HAVE_STATVFS)
|
||||
struct statvfs buf;
|
||||
return statvfs( path, &buf ) ? -1 : (int64_t)buf.f_bavail * (int64_t)buf.f_bsize;
|
||||
#else
|
||||
#warning FIXME: not implemented
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/* The following mmap functions are by Joerg Walter, and were taken from
|
||||
@@ -797,4 +826,3 @@ munmap_exit:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ const char * tr_getTorrentDir( const tr_session * );
|
||||
/** @brief return the directory where the Web Client's web ui files are kept */
|
||||
const char * tr_getWebClientDir( const tr_session * );
|
||||
|
||||
/** @brief return the number of bytes available for use in the specified path, or -1 on error */
|
||||
int64_t tr_getFreeSpace( const char * path );
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
@@ -1582,6 +1582,7 @@ sessionGet( tr_session * s,
|
||||
tr_bencDictAddInt ( d, "blocklist-size", tr_blocklistGetRuleCount( s ) );
|
||||
tr_bencDictAddStr ( d, "config-dir", tr_sessionGetConfigDir( s ) );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_sessionGetDownloadDir( s ) );
|
||||
tr_bencDictAddInt ( d, "download-dir-free-space", tr_sessionGetDownloadDirFreeSpace( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, tr_sessionGetPeerLimit( s ) );
|
||||
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, tr_sessionGetPeerLimitPerTorrent( s ) );
|
||||
tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_sessionGetIncompleteDir( s ) );
|
||||
@@ -1615,7 +1616,7 @@ sessionGet( tr_session * s,
|
||||
default: str = "preferred"; break;
|
||||
}
|
||||
tr_bencDictAddStr( d, TR_PREFS_KEY_ENCRYPTION, str );
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -882,6 +882,14 @@ tr_sessionGetDownloadDir( const tr_session * session )
|
||||
return session->downloadDir;
|
||||
}
|
||||
|
||||
int64_t
|
||||
tr_sessionGetDownloadDirFreeSpace( const tr_session * session )
|
||||
{
|
||||
assert( tr_isSession( session ) );
|
||||
|
||||
return tr_getFreeSpace( session->downloadDir );
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
@@ -338,6 +338,11 @@ void tr_sessionSetDownloadDir( tr_session * session, const char * downloadDir );
|
||||
*/
|
||||
const char * tr_sessionGetDownloadDir( const tr_session * session );
|
||||
|
||||
/**
|
||||
* @brief Get available disk space (in bytes) for the default download folder.
|
||||
* @return zero or positive integer on success, -1 in case of error.
|
||||
*/
|
||||
int64_t tr_sessionGetDownloadDirFreeSpace( const tr_session * session );
|
||||
|
||||
/**
|
||||
* @brief Set the torrent's bandwidth priority.
|
||||
|
||||
Reference in New Issue
Block a user