// File: /workspace/github_cpp_makefile_star2_O2/talyerushalmy[P]SimpleFileSystem/src/Commands.cpp
// Function: RmCommand::execute(FileSystem&)
void RmCommand::execute(FileSystem& fs)
{
	std::vector<std::string> arguments = StringTools::split(this->getArgs(), " ");

	if (arguments.size() != 1 || (arguments.size() > 0 && arguments[0] == ""))
	{
		std::cout << "Usage: rm <path>" << std::endl;
		return;
	}
	
	if (arguments[0] == "/")
	{
		std::cout << "Can't remove directory" << std::endl;
		return;
	}

	std::string src_name = StringTools::split(StringTools::trim(arguments[0]), "/").back();
	std::string src_dir = StringTools::trim(arguments[0]).substr(0, arguments[0].length() - src_name.length());

	Directory* src = fs.getDirectoryFromPath(src_dir);
	if (!src || !src->childExists(src_name))
	{
		std::cout << "No such file or directory" << std::endl;
		return;
	}

	BaseFile* bf = src->getChildByName(src_name);

	if (bf == &fs.getRootDirectory() || bf == &fs.getWorkingDirectory())
	{
		std::cout << "Can't remove directory" << std::endl;
		return;
	}

	src->removeFile(src_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
leaq 0x28(%rdi), %rsi
leaq -0x190(%rbp), %rdi
callq 0x3210
leaq 0x3d01(%rip), %rsi      # 0xb14b
leaq -0x170(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x30a0
leaq -0x30(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x348c
leaq -0x170(%rbp), %rdi
callq 0x30c0
leaq -0x190(%rbp), %rdi
callq 0x30c0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
subq %rdi, %rax
leaq 0x3e5b(%rip), %r14      # 0xb2f6
cmpq $0x20, %rax
jne 0x74cc
leaq 0x3ca4(%rip), %rsi      # 0xb14c
callq 0x8386
testb %al, %al
jne 0x74cc
movq -0x30(%rbp), %rdi
leaq 0x3d1f(%rip), %rsi      # 0xb1db
callq 0x8386
testb %al, %al
je 0x74fa
leaq 0x3e3b(%rip), %r14      # 0xb307
movq 0x9af5(%rip), %rdi      # 0x10fc8
movq %r14, %rsi
callq 0x3180
movq %rax, %rdi
callq 0x30d0
leaq -0x30(%rbp), %rdi
callq 0x3614
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x3574
leaq 0x3cca(%rip), %rsi      # 0xb1db
leaq -0x130(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x30a0
leaq -0x50(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x348c
movq -0x48(%rbp), %rsi
addq $-0x20, %rsi
leaq -0x70(%rbp), %rdi
callq 0x3210
leaq -0x50(%rbp), %rdi
callq 0x3614
leaq -0x130(%rbp), %rdi
callq 0x30c0
leaq -0x150(%rbp), %rdi
callq 0x30c0
movq -0x30(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x3574
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
subq -0x68(%rbp), %rcx
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rsi
xorl %edx, %edx
callq 0x31a0
leaq -0x90(%rbp), %rdi
callq 0x30c0
leaq -0x110(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3210
leaq -0x110(%rbp), %rsi
movq %rbx, %rdi
callq 0x8590
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0x30c0
testq %r14, %r14
je 0x7686
leaq -0xf0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3210
leaq -0xf0(%rbp), %rsi
movq %r14, %rdi
callq 0x90c2
movl %eax, %r15d
leaq -0xf0(%rbp), %rdi
callq 0x30c0
testb %r15b, %r15b
je 0x7686
leaq -0xd0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3210
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x94a4
movq %rax, %r15
leaq -0xd0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x8572
cmpq %rax, %r15
je 0x76a3
movq %rbx, %rdi
callq 0x857c
cmpq %rax, %r15
je 0x76a3
leaq -0xb0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3210
leaq -0xb0(%rbp), %rsi
movq %r14, %rdi
callq 0x9142
leaq -0xb0(%rbp), %rdi
callq 0x30c0
jmp 0x76be
movq 0x993b(%rip), %rdi      # 0x10fc8
leaq 0x3bd5(%rip), %rsi      # 0xb269
callq 0x3180
movq %rax, %rdi
callq 0x30d0
jmp 0x76be
movq 0x991e(%rip), %rdi      # 0x10fc8
leaq 0x3c56(%rip), %rsi      # 0xb307
callq 0x3180
movq %rax, %rdi
callq 0x30d0
leaq -0x50(%rbp), %rdi
callq 0x30c0
leaq -0x70(%rbp), %rdi
callq 0x30c0
jmp 0x74e3
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x7703
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0x7703
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x7703
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x30c0
jmp 0x774d
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x7751
movq %rax, %rbx
jmp 0x7756
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3614
jmp 0x772c
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x30c0
jmp 0x773d
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
jmp 0x775a
jmp 0x7783
jmp 0x774a
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x30c0
leaq -0x70(%rbp), %rdi
callq 0x30c0
jmp 0x7786
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
callq 0x30c0
jmp 0x7775
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x30c0
jmp 0x778f
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x3614
movq %rbx, %rdi
callq 0x3290
nop