MAC : How to check if the file is still being copied in cpp?

Posted by Peda Pola on Stack Overflow See other posts from Stack Overflow or by Peda Pola
Published on 2012-10-06T09:36:04Z Indexed on 2012/10/06 9:37 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

In my current project, we had a requirement to check if the file is still copying.

We have already developed a library which will give us OS notification like file_added , file_removed , file_modified, file_renamed on a particular folder along with the corresponding file path.

The problem here is that, lets say if you add 1 GB file, it is giving multiple notification such as file_added , file_modified, file_modified as the file is being copied.

Now i decided to surpass these notifications by checking if the file is copying or not. Based on that i will ignore events.

I have written below code which tells if the file is being copied or not which takes file path as input parameter. Details:- In Mac, while file is being copied the creation date is set as some date less than 1970. Once it is copied the date is set to current date. Am using this technique. Based on this am deciding that file is being copied.

Problem:- when we copy file in the terminal it is failing. Please advice me any approach.

bool isBeingCopied(const boost::filesystem::path &filePath)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    bool isBeingCopied = false;
    if([[[[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithUTF8String:filePath.string().c_str()] error:nil] fileCreationDate] timeIntervalSince1970] < 0)
    {
        isBeingCopied = true;
    }

    [pool release];
    return isBeingCopied;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about osx