Reputation: 2030
I have tried:
Checking the FSCatalogInfo
nodeFlags
to see if kFSNodeForkOpenBit
is set (using kFSNodeForkOpenMask
).
Checking whether the creator code is between kFirstMagicBusyFiletype
and kLastMagicBusyFiletype
.
Checking the ExtendedFileInfo
extendedFinderFlags
to see if kExtendedFlagObjectIsBusy
is set.
Running GetFileInfo -ab
from the shell.
All of these report that the file the Finder is copying to is not open.
Using lsof
does detect that the file is open, but (a) I don't want to call lsof
from my application, and (b) my understanding is that it relies on private API so looking at its source wouldn't help.
Upvotes: 5
Views: 7419
Reputation: 534
In Mac OS X v10.4 and later:
Whilst Finder progresses a copy of a file (not afterwards) the copy has:
brok
MACS
— together, those two things signify file business.
MACS
is the ID of Finder.
Whilst Finder progresses a copy of a file (not afterwards) the copy has a counterpart:
._
file that includes the necessary extended attribute (xattr).Why are dot underscore ._ files created, and how can I avoid them? — Ask Different
If a copy using Finder is interrupted ungracefully, then the presence of brok
MACS
should ensure that breakage/business is recognisable to:
A file big file.dmg
with no extended attribute.
Before copying from JHFS+ to an empty example
directory on a volume that uses MS-DOS (FAT32):
[macbookpro08:~] gjp22% date
Fri 11 May 2012 17:24:29 BST
[macbookpro08:~] gjp22% ls -h@al /Users/gjp22/Documents/uk/ac/brighton/collaborate/bigfile.dmg
-rw-r--r-- 1 gjp22 staff 1.4G 11 May 17:20 /Users/gjp22/Documents/uk/ac/brighton/collaborate/bigfile.dmg
[macbookpro08:~] gjp22% xattr /Users/gjp22/Documents/uk/ac/brighton/collaborate/bigfile.dmg
[macbookpro08:~] gjp22% diskutil list | grep FAT32
1: DOS_FAT_32 FAT32 2.0 GB disk3s1
[macbookpro08:~] gjp22% ls -h@al /Volumes/FAT32/example
total 16
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 17:24 .
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 11:32 ..
brokMACS
within the value of extended attribute com.apple.FinderInfo
:
[macbookpro08:~] gjp22% date
Fri 11 May 2012 17:25:08 BST
[macbookpro08:~] gjp22% ls -h@al /Volumes/FAT32/example
total 311320
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 17:25 .
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 11:32 ..
-rwxrwxrwx 1 gjp22 staff 4.0K 11 May 17:25 ._bigfile.dmg
-rwxrwxrwx@ 1 gjp22 staff 152M 11 May 17:25 bigfile.dmg
com.apple.FinderInfo 32B
[macbookpro08:~] gjp22% xattr -l /Volumes/FAT32/example/bigfile.dmg
com.apple.FinderInfo:
00000000 62 72 6F 6B 4D 41 43 53 00 00 00 00 00 00 00 00 |brokMACS........|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020
That extended attribute is removed:
[macbookpro08:~] gjp22% date
Fri 11 May 2012 17:29:19 BST
[macbookpro08:~] gjp22% xattr -l /Volumes/FAT32/example/bigfile.dmg
[macbookpro08:~] gjp22% ls -h@al /Volumes/FAT32/example
total 3000016
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 17:29 .
drwxrwxrwx 1 gjp22 staff 4.0K 11 May 11:32 ..
-rwxrwxrwx 1 gjp22 staff 1.4G 11 May 17:20 bigfile.dmg
Upvotes: 4
Reputation: 448
It's about 2 years too late for you now, but I thought for the sake of anybody finding this later I'd note that you can check the creation date of the file. Finder sets it to kMagicBusyCreationDate (1946-02-14 08:34:56 +0000) while it's copying.
Upvotes: 6
Reputation: 32468
It looks to me like partially copied files have a file type of "brok" and a creator code of "MACS".
I don't believe that the Finder marks in any way the copies of folders that it is in the process of making. The "grayed out" representation is strictly confined to the Finder process that is doing the copying. You can verify this by using Fast User Switching while a folder is copying: as a different user, the folder being copied has a normal appearance in the Finder, and you can open it and watch as sub-files and folders appear. The Finder doesn't seem to reveal any differences about the folder through AppleScript either, and I can't think of any other way to get that information.
Upvotes: 2
Reputation: 12053
I don't know the exact answer but... Below the POSIX and Carbon file mgr APIs there's another layer that is used by both. It's pretty close to VFS, and uses all lowercase names. You see those calls when you trace FS calls using the command "fs_usage", IIRC. You may find a working function in those calls. Unfortunately, they're not well documented. Hope that helps.
Upvotes: 0
Reputation: 12045
This method might be a little kludgey, but I've used it for similar purposes and it may work for you. The basic idea is to attempt opening the file with an exclusive lock, check to see if the open was successful, and then immediately close it again. So, this would look something like:
char* pathToFile;
int result;
result = open(pathToFile, O_RDWR | O_NONBLOCK | O_EXLOCK);
if (result != -1)
{
//The file is not busy
close(result);
}
else
{
//The file is busy
}
I've never tried this with a file being copied by the Finder, but it does work when a file is open by another application on the system. I'm not sure if this same method works if you open it as read-only instead of read/write, so that might be another gotcha depending on your requirements.
Upvotes: 0