node.py: use NODEDIR/tmp for the 'tempfile' module's temporary directory, so webapi upload tempfiles are put there instead of /tmp . You can set it to something else by setting [node]tempdir in tahoe.cfg

This commit is contained in:
Brian Warner 2009-01-14 20:00:15 -07:00
parent e9d4334159
commit 26ca53fa3d
2 changed files with 29 additions and 2 deletions

View File

@ -205,6 +205,18 @@ ssh.authorized_keys_file = (filename, optional)
ssh.port = 8022 ssh.port = 8022
ssh.authorized_keys_file = ~/.ssh/authorized_keys ssh.authorized_keys_file = ~/.ssh/authorized_keys
tempdir = (string, optional)
This specifies a temporary directory for the webapi server to use, for
holding large files while they are being uploaded. If a webapi client
attempts to upload a 10GB file, this tempdir will need to have at least 10GB
available for the upload to complete.
The default value is the "tmp" directory in the node's base directory (i.e.
$NODEDIR/tmp), but it can be placed elsewhere. This directory is used for
files that usually (on a unix system) go into /tmp . The string will be
interpreted relative to the node's base directory.
== Client Configuration == == Client Configuration ==
[client] [client]

View File

@ -1,5 +1,5 @@
import datetime, os.path, re, types, ConfigParser import datetime, os.path, re, types, ConfigParser, tempfile
from base64 import b32decode, b32encode from base64 import b32decode, b32encode
from twisted.python import log as twlog from twisted.python import log as twlog
@ -10,7 +10,7 @@ import foolscap.logging.log
from allmydata import get_package_versions, get_package_versions_string from allmydata import get_package_versions, get_package_versions_string
from allmydata.util import log from allmydata.util import log
from allmydata.util import fileutil, iputil, observer from allmydata.util import fileutil, iputil, observer
from allmydata.util.assertutil import precondition from allmydata.util.assertutil import precondition, _assert
from foolscap.logging import app_versions from foolscap.logging import app_versions
@ -65,6 +65,7 @@ class Node(service.MultiService):
nickname_utf8 = self.get_config("node", "nickname", "<unspecified>") nickname_utf8 = self.get_config("node", "nickname", "<unspecified>")
self.nickname = nickname_utf8.decode("utf-8") self.nickname = nickname_utf8.decode("utf-8")
self.init_tempdir()
self.create_tub() self.create_tub()
self.logSource="Node" self.logSource="Node"
@ -73,6 +74,20 @@ class Node(service.MultiService):
self.log("Node constructed. " + get_package_versions_string()) self.log("Node constructed. " + get_package_versions_string())
iputil.increase_rlimits() iputil.increase_rlimits()
def init_tempdir(self):
local_tempdir = "tmp" # default is NODEDIR/tmp/
tempdir = self.get_config("node", "tempdir", local_tempdir)
tempdir = os.path.join(self.basedir, tempdir)
if not os.path.exists(tempdir):
fileutil.make_dirs(tempdir)
tempfile.tempdir = os.path.abspath(tempdir)
# this should cause twisted.web.http (which uses
# tempfile.TemporaryFile) to put large request bodies in the given
# directory. Without this, the default temp dir is usually /tmp/,
# which is frequently too small.
test_name = tempfile.mktemp()
_assert(os.path.dirname(test_name) == tempdir, test_name, tempdir)
def get_config(self, section, option, default=_None, boolean=False): def get_config(self, section, option, default=_None, boolean=False):
try: try:
if boolean: if boolean: