Esempio n. 1
0
def DeleteBackup(request):
    if request.Payload == '':
        ids = [request.PacketID]
    else:
        ids = request.Payload.split('\n')
    count = 0
    for backupID in ids:
        filename = makeFilename(request.OwnerID, backupID)
        if filename == "":
            filename = constructFilename(request.OwnerID, backupID)
            if not os.path.exists(filename):
                dhnio.Dprint(1, "p2p_service.DeleteBackup WARNING had unknown customer " + request.OwnerID + " or backupID " + backupID)
                return
        if os.path.isdir(filename):
            try:
                dhnio._dir_remove(filename)
                count += 1
            except:
                dhnio.DprintException()
        elif os.path.isfile(filename):
            try:
                os.remove(filename)
                count += 1
            except:
                dhnio.DprintException()
        else:
            dhnio.Dprint(1, "p2p_service.DeleteBackup WARNING path not found %s" % filename)
    transport_control.SendAck(request)
    dhnio.Dprint(6, "p2p_service.DeleteBackup from [%s] with %d IDs, %d were removed" % (nameurl.GetName(request.OwnerID), len(ids), count))
Esempio n. 2
0
def DeleteFile(request):
    if request.Payload == '':
        ids = [request.PacketID]
    else:
        ids = request.Payload.split('\n')
    filescount = 0
    dirscount = 0
    for pathID in ids:
        filename = makeFilename(request.OwnerID, pathID)
        if filename == "":
            filename = constructFilename(request.OwnerID, pathID)
            if not os.path.exists(filename):
                dhnio.Dprint(1, "p2p_service.DeleteFile WARNING had unknown customer: %s or pathID is not correct or not exist: %s" % (nameurl.GetName(request.OwnerID), pathID))
                return
        if os.path.isfile(filename):
            try:
                os.remove(filename)
                filescount += 1
            except:
                dhnio.DprintException()
        elif os.path.isdir(filename):
            try:
                dhnio._dir_remove(filename)
                dirscount += 1
            except:
                dhnio.DprintException()
        else:
            dhnio.Dprint(1, "p2p_service.DeleteFile WARNING path not found %s" % filename)
    dhnio.Dprint(6, "p2p_service.DeleteFile from [%s] with %d IDs, %d files and %d folders were removed" % (
        nameurl.GetName(request.OwnerID), len(ids), filescount, dirscount))
    transport_control.SendAck(request)
Esempio n. 3
0
def UpdateCustomers():
    printlog("UpdateCustomers " + str(time.strftime("%a, %d %b %Y %H:%M:%S +0000")))
    space = dhnio._read_dict(CustomersSpaceFile())
    if space is None:
        printlog("UpdateCustomers ERROR space file can not read")
        return
    customers_dir = getCustomersFilesDir()
    if not os.path.exists(customers_dir):
        printlog("UpdateCustomers ERROR customers folder not exist")
        return
    remove_list = {}
    for customer_filename in os.listdir(customers_dir):
        onecustdir = os.path.join(customers_dir, customer_filename)
        if not os.path.isdir(onecustdir):
            remove_list[onecustdir] = "is not a folder"
            continue
        idurl = FilenameUrl(customer_filename)
        if idurl is None:
            remove_list[onecustdir] = "wrong folder name"
            continue
        curspace = space.get(idurl, None)
        if curspace is None:
            remove_list[onecustdir] = "is not a customer"
            continue
    for path in remove_list.keys():
        if not os.path.exists(path):
            continue
        if os.path.isdir(path):
            try:
                dhnio._dir_remove(path)
                printlog("UpdateCustomers " + path + " folder removed (%s)" % (remove_list[path]))
            except:
                printlog("UpdateCustomers ERROR removing " + path)
            continue
        if not os.access(path, os.W_OK):
            os.chmod(path, 0600)
        try:
            os.remove(path)
            printlog("UpdateCustomers " + path + " file removed (%s)" % (remove_list[path]))
        except:
            printlog("UpdateCustomers ERROR removing " + path)
Esempio n. 4
0
def SpaceTime():
    printlog("SpaceTime " + str(time.strftime("%a, %d %b %Y %H:%M:%S +0000")))
    space = dhnio._read_dict(CustomersSpaceFile())
    if space is None:
        printlog("SpaceTime ERROR can not read file " + CustomersSpaceFile())
        return
    customers_dir = getCustomersFilesDir()
    if not os.path.exists(customers_dir):
        printlog("SpaceTime ERROR customers folder not exist")
        return
    remove_list = {}
    for customer_filename in os.listdir(customers_dir):
        onecustdir = os.path.join(customers_dir, customer_filename)
        if not os.path.isdir(onecustdir):
            remove_list[onecustdir] = "is not a folder"
            continue
        idurl = FilenameUrl(customer_filename)
        if idurl is None:
            remove_list[onecustdir] = "wrong folder name"
            continue
        curspace = space.get(idurl, None)
        if curspace is None:
            continue
        try:
            maxspaceV = int(float(curspace) * 1024 * 1024)  # in bytes
        except:
            remove_list[onecustdir] = "wrong space value"
            continue
        timedict = {}
        sizedict = {}

        def cb(path, subpath, name):
            if not os.access(path, os.R_OK | os.W_OK):
                return False
            if not os.path.isfile(path):
                return True
            if name in [BackupIndexFileName()]:
                return False
            stats = os.stat(path)
            timedict[path] = stats.st_ctime
            sizedict[path] = stats.st_size

        dhnio.traverse_dir_recursive(cb, onecustdir)
        currentV = 0
        for path in sorted(timedict.keys(), key=lambda x: timedict[x], reverse=True):
            currentV += sizedict.get(path, 0)
            if currentV < maxspaceV:
                continue
            try:
                os.remove(path)
                printlog("SpaceTime " + path + " file removed (cur:%s, max: %s)" % (str(currentV), str(maxspaceV)))
            except:
                printlog("SpaceTime ERROR removing " + path)
            time.sleep(0.1)
        timedict.clear()
        sizedict.clear()
    for path in remove_list.keys():
        if not os.path.exists(path):
            continue
        if os.path.isdir(path):
            try:
                dhnio._dir_remove(path)
                printlog("SpaceTime " + path + " dir removed (%s)" % (remove_list[path]))
            except:
                printlog("SpaceTime ERROR removing " + path)
            continue
        if not os.access(path, os.W_OK):
            os.chmod(path, 0600)
        try:
            os.remove(path)
            printlog("SpaceTime " + path + " file removed (%s)" % (remove_list[path]))
        except:
            printlog("SpaceTime ERROR removing " + path)
    del remove_list