Discussion:
[Twisted-Python] dcc, idea for file resume
peter
2015-10-12 18:01:00 UTC
Permalink
hi,


the way file resume is implemented in DccFileReceive requires to user to
determine the file size manually and set _resumeOffset.
wouldnt it make sene to just kill the last few bytes of the file and
resume it?

below is the current connectionMade method from:
http://twistedmatrix.com/trac/browser/tags/releases/twisted-15.4.0/twisted/words/protocols/irc.py#L3013


replace this line:
self.file.seek(self._resumeOffset)

with:
self.file.seek(-3,2)


which removes the last 3 bytes from the file end, 3 is just a guess.


def connectionMade(self):
dst = path.abspath(path.join(self.destDir,self.filename))
exists = path.exists(dst)
if self.resume and exists:
print "yes i want to resume and the file is there"
# I have been told I want to resume, and a file already
# exists - Here we go
self.file = open(dst, 'rb+')
self.file.seek(-3,2)
self.file.truncate()
log.msg("Attempting to resume %s - starting from %d bytes" %
(self.file, self.file.tell()))
elif self.resume and not exists:
raise OSError(errno.ENOENT,
"You cannot resume writing to a file "
"that does not exist!",
dst)
elif self.overwrite or not exists:
self.file = open(dst, 'wb')
else:
raise OSError(errno.EEXIST,
"There's a file in the way. "
"Perhaps that's why you cannot open it.",
dst)
Glyph Lefkowitz
2015-10-13 00:51:49 UTC
Permalink
hi,
the way file resume is implemented in DccFileReceive requires to user to determine the file size manually and set _resumeOffset.
wouldnt it make sene to just kill the last few bytes of the file and resume it?
http://twistedmatrix.com/trac/browser/tags/releases/twisted-15.4.0/twisted/words/protocols/irc.py#L3013 <http://twistedmatrix.com/trac/browser/tags/releases/twisted-15.4.0/twisted/words/protocols/irc.py#L3013>
self.file.seek(self._resumeOffset)
self.file.seek(-3,2)
which removes the last 3 bytes from the file end, 3 is just a guess.
Why remove the last 3 bytes? It seems like either the file's contents are valid or not; if they are, just trust everything that's there, if not, don't try to resume...

Generally though this does sound like a good change! Don't make the user guess if we can just do the right thing for them. Can you open a ticket?

-glyph
peter
2015-10-21 16:31:08 UTC
Permalink
Post by Glyph Lefkowitz
Post by peter
hi,
the way file resume is implemented in DccFileReceive requires to user
to determine the file size manually and set _resumeOffset.
wouldnt it make sene to just kill the last few bytes of the file and resume it?
http://twistedmatrix.com/trac/browser/tags/releases/twisted-15.4.0/twisted/words/protocols/irc.py#L3013
self.file.seek(self._resumeOffset)
self.file.seek(-3,2)
which removes the last 3 bytes from the file end, 3 is just a guess.
Why remove the last 3 bytes? It seems like either the file's contents
are valid or not; if they are, just trust everything that's there, if
not, don't try to resume...
Generally though this does sound like a good change! Don't make the
user guess if we can just do the right thing for them. Can you open a
ticket?
-glyph
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
sorry for the late reply, missed the message.
sure i will.

Continue reading on narkive:
Loading...