import os

def managerFiles(paths, link):
	first = True
	src = ""
	for path in paths:
		if first:
			first = False
			src = path
			print("PRESERVED: The file preserved is: \"" + path + "\"")

		else:
			os.remove(path)
			print("DELETE: File deleted: \"" + path + "\"")

			if link:
				os.symlink(src, path)
				print("LINK: Created link: \"" + path + "\" -> \"" + src + "\"")


# Try The Voight-Kampff if you not recognize if is a replicant or not, all is suspect
def manager(duplicates, createLink = False):
	if len(duplicates) < 1:
		print("No duplicates found")
		print("Great! Bye!")
		exit(0)

	for filesByHash in duplicates.values():
		managerFiles(filesByHash, createLink)


def delete(duplicates):
	manager(duplicates)

def link(duplicates):
	manager(duplicates, True)

import os
from threading import Thread

def _delete(path):
	os.remove(path)

def _link(src, path):
	os.symlink(src, path)

def manager_files(paths, link):
	# The first file is preserved to not delete all files in directories.
	first = True
	src = ""
	deleted_files = []
	linked_files = []
	errors = []
	
	for path in paths:
		if os.path.isfile(path):
			if first:
				first = False
				src = path
			
			else:
				Thread(target=_delete, args=(path)).start()
				deleted_files.append(path)
				
				if link:
					Thread(target=_link, args=(src, path)).start()
					linked_files.append(path)
		else:
			errors.append("Not identified by file: \"{}\"".format(path))
	
	return {"preserved": src, "linked_files": linked_files, "deleted_files": deleted_files, "errors": errors}


# Try The Voight-Kampff if you not recognize if is a replicant or not, all is suspect
def manager(duplicates, create_link=False):
	if len(duplicates) == 0:
		return None
	
	processed_files = []
	for files_by_hash in duplicates.values():
		processed_files.append(manager_files(files_by_hash, create_link))
	
	return processed_files


def delete(duplicates):
	return manager(duplicates)



def link(duplicates):
	return manager(duplicates, True)

Adjust spaces and names of variables. Add format of thread to delete and link files. Add to methods of link, delete results of files deleted, linked and with error to list and return for caller method.
Adjust spaces and names of variables.
Add format of thread to delete and link files.
Add to methods of link, delete results of files deleted, linked and with error to list and return for caller method.

Signed-off-by: messiasthi <8562fc1efba9a3c99753c749fdfb1b6932b70fbf@gmail.com>
