Fixing issue #26, with the server not creating the full path to the filename
being uploaded.
This commit is contained in:
parent
9b655fcaa1
commit
05e56b66a4
3 changed files with 30 additions and 17 deletions
|
@ -141,12 +141,14 @@ class TestTftpyState(unittest.TestCase):
|
|||
def setUp(self):
|
||||
tftpy.setLogLevel(logging.DEBUG)
|
||||
|
||||
def clientServerUploadOptions(self, options):
|
||||
def clientServerUploadOptions(self, options, transmitname=None):
|
||||
"""Fire up a client and a server and do an upload."""
|
||||
root = '/tmp'
|
||||
home = os.path.dirname(os.path.abspath(__file__))
|
||||
filename = '100KBFILE'
|
||||
input_path = os.path.join(home, filename)
|
||||
if transmitname:
|
||||
filename = transmitname
|
||||
server = tftpy.TftpServer(root)
|
||||
client = tftpy.TftpClient('localhost',
|
||||
20001,
|
||||
|
@ -198,6 +200,9 @@ class TestTftpyState(unittest.TestCase):
|
|||
def testClientServerUploadNoOptions(self):
|
||||
self.clientServerUploadOptions({})
|
||||
|
||||
def testClientServerUploadWithSubdirs(self):
|
||||
self.clientServerUploadOptions({}, transmitname='foo/bar/100KBFILE')
|
||||
|
||||
def testClientServerUploadOptions(self):
|
||||
for blksize in [512, 1024, 2048, 4096]:
|
||||
self.clientServerUploadOptions({'blksize': blksize})
|
||||
|
@ -208,7 +213,6 @@ class TestTftpyState(unittest.TestCase):
|
|||
tftpy.TftpStates.DELAY_BLOCK = 0
|
||||
|
||||
def testServerNoOptions(self):
|
||||
"""Test the server states."""
|
||||
raddress = '127.0.0.2'
|
||||
rport = 10000
|
||||
timeout = 5
|
||||
|
@ -246,7 +250,6 @@ class TestTftpyState(unittest.TestCase):
|
|||
self.assertTrue( finalstate is None )
|
||||
|
||||
def testServerNoOptionsSubdir(self):
|
||||
"""Test the server states."""
|
||||
raddress = '127.0.0.2'
|
||||
rport = 10000
|
||||
timeout = 5
|
||||
|
|
|
@ -79,12 +79,12 @@ class TftpClient(TftpSession):
|
|||
|
||||
Note: If output is a hyphen then stdout is used."""
|
||||
self.context = TftpContextClientUpload(self.host,
|
||||
self.iport,
|
||||
filename,
|
||||
input,
|
||||
self.options,
|
||||
packethook,
|
||||
timeout)
|
||||
self.iport,
|
||||
filename,
|
||||
input,
|
||||
self.options,
|
||||
packethook,
|
||||
timeout)
|
||||
self.context.start()
|
||||
# Upload happens here
|
||||
self.context.end()
|
||||
|
|
|
@ -209,8 +209,14 @@ class TftpState(object):
|
|||
% (self.context.last_pkt, self))
|
||||
self.context.metrics.resent_bytes += len(self.context.last_pkt.buffer)
|
||||
self.context.metrics.add_dup(self.context.last_pkt)
|
||||
sendto_port = self.context.tidport
|
||||
if not sendto_port:
|
||||
# If the tidport wasn't set, then the remote end hasn't even
|
||||
# started talking to us yet. That's not good. Maybe it's not
|
||||
# there.
|
||||
sendto_port = self.context.port
|
||||
self.context.sock.sendto(self.context.last_pkt.encode().buffer,
|
||||
(self.context.host, self.context.tidport))
|
||||
(self.context.host, sendto_port))
|
||||
if self.context.packethook:
|
||||
self.context.packethook(self.context.last_pkt)
|
||||
|
||||
|
@ -307,16 +313,20 @@ class TftpStateServerRecvWRQ(TftpState):
|
|||
"""The purpose of this method is to, if necessary, create all of the
|
||||
subdirectories leading up to the file to the written."""
|
||||
# Pull off everything below the root.
|
||||
subpath = self.full_path[:len(self.context.root)]
|
||||
subpath = self.full_path[len(self.context.root):]
|
||||
log.debug("make_subdirs: subpath is %s" % subpath)
|
||||
dirs = subpath.split(os.sep)
|
||||
# Split on directory separators, but drop the last one, as it should
|
||||
# be the filename.
|
||||
dirs = subpath.split(os.sep)[:-1]
|
||||
log.debug("dirs is %s" % dirs)
|
||||
current = self.context.root
|
||||
for dir in dirs:
|
||||
current = os.path.join(current, dir)
|
||||
if os.path.isdir(current):
|
||||
log.debug("%s is already an existing directory" % current)
|
||||
else:
|
||||
os.mkdir(current, 0700)
|
||||
if dir:
|
||||
current = os.path.join(current, dir)
|
||||
if os.path.isdir(current):
|
||||
log.debug("%s is already an existing directory" % current)
|
||||
else:
|
||||
os.mkdir(current, 0700)
|
||||
|
||||
def handle(self, pkt, raddress, rport):
|
||||
"Handle an initial WRQ packet as a server."
|
||||
|
|
Reference in a new issue