Changeset - 0ad71a952f92
[Not reviewed]
default
0 3 0
Laman - 7 years ago 2018-01-02 20:44:31

handled locked exception on pull
3 files changed with 18 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/client.py
Show inline comments
 
@@ -8,7 +8,7 @@ import config as conf
 
import stats
 
from util import Progress
 
from hashtree import HashTree,hashBlock
 
from netnode import BaseConnection,NetNode,FailedConnection
 
from netnode import BaseConnection,NetNode,FailedConnection,LockedException
 

	
 

	
 
class DeniedConnection(Exception): pass
 
@@ -125,8 +125,13 @@ class Client(NetNode):
 
		log.info("closing session...")
 
		dataFile.close()
 

	
 
	def pullData(self,blocksToTransfer):
 
		self._lock()
 
	def pullData(self,blocksToTransfer,ignoreLock=False):
 
		if not ignoreLock:
 
			try:
 
				self._lock()
 
			except LockedException:
 
				print("The file is locked. Either (a) there's another pull going on (then wait or kill it), or (b) a previous pull ended prematurely and the file is probably corrupt (then repeat pull with -f for force).")
 
				return
 
		log.info(blocksToTransfer)
 
		dataFile=open(self._filename, mode="rb+")
 
		i1=-1
src/morevna.py
Show inline comments
 
@@ -67,7 +67,7 @@ def pull(args):
 
			c.setConnection(con)
 
			c.init("pull")
 
			blocksToTransfer=c.negotiate()
 
			c.pullData(blocksToTransfer)
 
			c.pullData(blocksToTransfer,args.force)
 
		print()
 
		print(stats.report())
 
	except FailedConnection: pass
 
@@ -108,6 +108,7 @@ pUpdate=subparsers.add_parser("pull")
 
pUpdate.add_argument("-p","--port",type=int)
 
pUpdate.add_argument("--host")
 
pUpdate.add_argument("-t","--tree",help="stored hash tree location")
 
pUpdate.add_argument("-f","--force",action="store_true",help="ignore lock file")
 
pUpdate.add_argument("datafile")
 
pUpdate.set_defaults(func=pull)
 

	
src/morevna.sh
Show inline comments
 
#!/bin/bash
 

	
 
# setup encrypted container
 
#sudo losetup -f ext2.img
 
#sudo cryptsetup open --type=luks /dev/loop0 ext2luks
 
@@ -6,12 +8,15 @@
 
# generate certificate
 
# openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=name"
 

	
 
set -e
 
DIRNAME=`dirname $0`
 

	
 
sudo losetup -f ~/ext2.img
 
sudo cryptsetup open --type=luks /dev/loop0 ext2luks
 
sudo mount /dev/mapper/ext2luks ~/temp
 

	
 
sudo rdiff-backup -v 5 ~/Dokumenty ~/temp/Dokumenty
 
sudo rdiff-backup -v 5 ~/Projekty ~/temp/Projekty
 
sudo rdiff-backup -v 5 --exclude '**/__pycache__/' ~/Projekty ~/temp/Projekty
 
sudo rdiff-backup -v 5 ~/Obrázky ~/temp/Obrázky
 

	
 
sudo umount /dev/mapper/ext2luks
 
@@ -20,5 +25,5 @@ sudo losetup -d /dev/loop0
 

	
 
echo
 

	
 
python morevna.py build ~/ext2.bin ~/ext2.img
 
python morevna.py push --tree ~/ext2.bin ~/ext2.img
 
python $DIRNAME/morevna.py build ~/ext2.bin ~/ext2.img
 
python $DIRNAME/morevna.py push --tree ~/ext2.bin ~/ext2.img
0 comments (0 inline, 0 general)