// File: luisremis[P]SDFS/FileSystem.cpp
// Function: FileSystem::checkFiles()
void FileSystem::checkFiles()
{
    // hashing function to find the machine/s where to store the file;
    
    std::vector<std::string> toremove;

    filesLock.lock();

    for ( auto &file : files)
    {
        int flag = false;
        for (int i = 0; i < 3; ++i)
        {
            int position = findPositionByKey( hashString(file.filename) ) + i;
            int nodePosition = ( position + virtualRing.size() ) % virtualRing.size();

            if (virtualRing[nodePosition].key == myself.key)
            {
                flag = true;
            }
        }

        if (!flag)
        {
            toremove.push_back(file.filename);
        }
    }

    for (int i = 0; i < toremove.size(); ++i)
    {
        if ( deleteFile( toremove.at(i) ) ) 
        {
            logFile << toremove.at(i) << "deleted" << std::endl;
        }
        files.remove(toremove.at(i));
    }

    filesLock.unlock();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xb510
movq -0xf8(%rbp), %rdi
addq $0x228, %rdi            # imm = 0x228
callq 0xb5f0
jmp 0x12648
movq -0xf8(%rbp), %rax
addq $0x210, %rax            # imm = 0x210
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x164c0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x164f0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x16520
testb $0x1, %al
jne 0x12689
jmp 0x127f0
leaq -0x40(%rbp), %rdi
callq 0x16550
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x3, -0x58(%rbp)
jge 0x127c9
movq -0x50(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x41e0
jmp 0x126bd
leaq -0x80(%rbp), %rdi
callq 0x10600
movq -0xf8(%rbp), %rdi
movl %eax, %esi
callq 0x11010
movl %eax, -0xfc(%rbp)
jmp 0x126dc
movl -0xfc(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x42a0
movl -0x114(%rbp), %eax
movq -0xf8(%rbp), %rdi
movl %eax, -0x5c(%rbp)
movslq -0x5c(%rbp), %rax
movq %rax, -0x110(%rbp)
addq $0x250, %rdi            # imm = 0x250
callq 0x16470
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movq -0x110(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x108(%rbp)
addq $0x250, %rdi            # imm = 0x250
callq 0x16470
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movq -0x108(%rbp), %rax
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x84(%rbp)
addq $0x250, %rdi            # imm = 0x250
movslq -0x84(%rbp), %rsi
callq 0x164a0
movq -0xf8(%rbp), %rcx
movl 0x20(%rax), %eax
cmpl 0x2b8(%rcx), %eax
jne 0x127b9
movl $0x1, -0x54(%rbp)
jmp 0x127b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x12a0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x42a0
jmp 0x12a0e
jmp 0x127bb
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x126a4
cmpl $0x0, -0x54(%rbp)
jne 0x127e0
movq -0x50(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0xb9e0
jmp 0x127de
jmp 0x127e0
jmp 0x127e2
leaq -0x40(%rbp), %rdi
callq 0x16570
jmp 0x12673
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xd610
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x129e7
movslq -0x88(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x16590
movq %rax, -0x128(%rbp)
jmp 0x1283d
movq -0x128(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x41e0
jmp 0x12852
movq -0xf8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x12a20
movb %al, -0x129(%rbp)
jmp 0x1286d
leaq -0xa8(%rbp), %rdi
callq 0x42a0
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x12888
jmp 0x1291b
movq -0xf8(%rbp), %rax
movq %rax, -0x140(%rbp)
movslq -0x88(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x16590
movq %rax, -0x138(%rbp)
jmp 0x128af
movq -0x138(%rbp), %rsi
movq -0x140(%rbp), %rdi
callq 0x4370
movq %rax, -0x148(%rbp)
jmp 0x128cb
movq -0x148(%rbp), %rdi
leaq 0xa1d2(%rip), %rsi      # 0x1caab
callq 0x43f0
movq %rax, -0x150(%rbp)
jmp 0x128e7
movq -0x150(%rbp), %rdi
movq 0x146b3(%rip), %rsi     # 0x26fa8
callq 0x4410
jmp 0x128fc
jmp 0x1291b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x42a0
jmp 0x12a0e
movq -0xf8(%rbp), %rax
addq $0x210, %rax            # imm = 0x210
movq %rax, -0x160(%rbp)
movslq -0x88(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x16590
movq %rax, -0x158(%rbp)
jmp 0x12948
movq -0x158(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x41e0
jmp 0x1295d
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x142e0
jmp 0x12972
movq -0x160(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x165d0
jmp 0x12987
leaq -0xd0(%rbp), %rdi
callq 0x166f0
leaq -0xf0(%rbp), %rdi
callq 0x42a0
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x127fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x129d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x166f0
leaq -0xf0(%rbp), %rdi
callq 0x42a0
jmp 0x12a0e
movq -0xf8(%rbp), %rdi
addq $0x228, %rdi            # imm = 0x228
callq 0xb620
jmp 0x129fc
leaq -0x20(%rbp), %rdi
callq 0xb870
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0xb870
movq -0x28(%rbp), %rdi
callq 0x46a0