Browse Source

Fixed bug with temp dir

need to address the same file in different places
restore_refactor
Raphael Roberts 7 years ago
parent
commit
76ec829782
  1. 5
      backup.py
  2. 12
      restore.py

5
backup.py

@ -1,11 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
from imohash.imohash import hashfile as _imohash from imohash.imohash import hashfile as _imohash
import argparse
import hashlib import hashlib
import multiprocessing
import os import os
import psutil import psutil
import sqlite3 import sqlite3
import argparse
# https://stackoverflow.com/a/17782753 # https://stackoverflow.com/a/17782753
def file_hash(path, block_size=4096*8): def file_hash(path, block_size=4096*8):
''' '''
@ -40,7 +40,6 @@ def hashify(top):
real_hash = None real_hash = None
if imohash in imo_hashes: if imohash in imo_hashes:
real_hash = file_hash(filepath) real_hash = file_hash(filepath)
print(file)
ret.append( ret.append(
( (
filepath, filepath,

12
restore.py

@ -1,13 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
from backup import hashify from backup import hashify
import argparse import argparse
import datetime
import time
import shutil
import os import os
import shutil
import sqlite3 import sqlite3
import time
import time
def create_temp(): def create_temp():
name= 'fsb{}'.format(datetime.datetime.today())
name= 'fsb{}'.format(hex(time.time_ns())[2:])
os.mkdir(name) os.mkdir(name)
return name return name
def lookup(cur,imohash,realhash=None): def lookup(cur,imohash,realhash=None):
@ -30,7 +31,8 @@ def restore(database,source,destination):
parent = os.path.dirname(qpath) parent = os.path.dirname(qpath)
if not os.path.exists(parent): if not os.path.exists(parent):
os.makedirs(parent) os.makedirs(parent)
shutil.move(ppath,qpath)
print(ppath,qpath,sep = '->')
os.rename(ppath,qpath)
os.rename(temp,destination) os.rename(temp,destination)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()

Loading…
Cancel
Save