Skip to content

Commit

Permalink
fixed file upload/download
Browse files Browse the repository at this point in the history
  • Loading branch information
vesellov committed Sep 19, 2018
1 parent 95e0ade commit 1b9799b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion p2p/lookup.py
Expand Up @@ -429,7 +429,7 @@ def _on_node_observe_failed(self, err, arg=None):
try:
self.failed += 1
if _Debug:
lg.warn('%r : %r' % (arg, err))
lg.warn('%r : %s' % (arg, strng.to_string(err, errors='ignore')))
except:
lg.exc()
return None
Expand Down
18 changes: 10 additions & 8 deletions raid/make.py
Expand Up @@ -49,8 +49,6 @@
#------------------------------------------------------------------------------

from __future__ import absolute_import
import six
from six.moves import range
from io import open

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -127,8 +125,12 @@ def ReadBinaryFile(filename):
def WriteFile(filename, data):
"""
"""
if sys.version_info[0] == 3:
binary_type = bytes
else:
binary_type = str
s = data
if not isinstance(s, six.binary_type):
if not isinstance(s, binary_type):
s = s.encode('utf-8')
f = open(filename, "wb")
f.write(s)
Expand Down Expand Up @@ -164,11 +166,11 @@ def do_in_memory(filename, eccmapname, version, blockNumber, targetDir):
for i in range(seglength):
offset = segoffset + i
if offset < length:
f.write(wholefile[offset].encode('utf-8'))
f.write(wholefile[offset])
else:
# any padding should go at the end of last seg
# and block.Length fixes
f.write(" ".encode('utf-8'))
f.write(" ")
f.close()

dfds = {}
Expand Down Expand Up @@ -259,11 +261,11 @@ def do_with_files(filename, eccmapname, version, blockNumber, targetDir):
for i in range(seglength):
offset = segoffset + i
if (offset < length):
f.write(wholefile[offset].encode('utf-8'))
f.write(wholefile[offset])
else:
# any padding should go at the end of last seg
# and block.Length fixes
f.write(" ".encode('utf-8'))
f.write(" ")
f.close()
del wholefile

Expand Down Expand Up @@ -303,7 +305,7 @@ def do_with_files(filename, eccmapname, version, blockNumber, targetDir):

for PSegNum in range(myeccmap.paritysegments):
bstr = struct.pack(">l", Parities[PSegNum])
pfds[PSegNum].write(bstr).encode('utf-8')
pfds[PSegNum].write(bstr)

dataNum = 0
parityNum = 0
Expand Down
1 change: 1 addition & 0 deletions raid/raid_worker.py
Expand Up @@ -88,6 +88,7 @@

_MODULES = (
'os',
'sys',
'cStringIO',
'struct',
'logs.lg',
Expand Down
23 changes: 10 additions & 13 deletions raid/read.py
Expand Up @@ -94,13 +94,10 @@ def ReadBinaryFile(filename):
return ''
if not os.access(filename, os.R_OK):
return ''
try:
fin = open(filename, "rb")
data = fin.read().encode('utf-8')
fin.close()
return data
except:
return ''
f = open(filename, "rb")
data = f.read()
f.close()
return data

# RebuildOne_new and RebuildOne_orig are just for debugging purposes

Expand All @@ -123,7 +120,7 @@ def RebuildOne(inlist, listlen, outfilename):
rebuildfile = open(outfilename, "wb")
while True:
for k in range(listlen):
raidreads[k] = raidfiles[k].read(2048).decode('utf-8')
raidreads[k] = raidfiles[k].read(2048)
if not raidreads[0]:
break
i = 0
Expand All @@ -132,7 +129,7 @@ def RebuildOne(inlist, listlen, outfilename):
for j in range(listlen):
b1 = ord(raidreads[j][i])
xor = xor ^ b1
rebuildfile.write(chr(xor).encode('utf-8'))
rebuildfile.write(chr(xor))
i += readsize
for filenum in range(listlen):
raidfiles[filenum].close()
Expand Down Expand Up @@ -171,11 +168,11 @@ def RebuildOne_orig(inlist, listlen, outfilename):
for i in range(0, seglength / INTSIZE):
xor = 0
for j in range(0, listlen):
bstr1 = fds[j].read(INTSIZE).decode('utf-8')
bstr1 = fds[j].read(INTSIZE)
b1, = struct.unpack(">l", bstr1)
xor = xor ^ b1
outstr = struct.pack(">l", xor)
fout.write(outstr.encode('utf-8'))
fout.write(outstr)
for filenum in range(0, listlen):
fds[filenum].close

Expand Down Expand Up @@ -243,8 +240,8 @@ def raidread(
'-Data')
if os.path.exists(FileName):
GoodDSegs += 1
moredata = open(FileName, "rb").read().decode('utf-8')
output.write(moredata.encode('utf-8'))
moredata = open(FileName, "rb").read()
output.write(moredata)
output.close()
return GoodDSegs
# except:
Expand Down

0 comments on commit 1b9799b

Please sign in to comment.