Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if a file or folder is busy, e.g. the Finder is busy copying to it?

Tags:

macos

I have tried:

  1. Checking the FSCatalogInfo nodeFlags to see if kFSNodeForkOpenBit is set (using kFSNodeForkOpenMask).

  2. Checking whether the creator code is between kFirstMagicBusyFiletype and kLastMagicBusyFiletype.

  3. Checking the ExtendedFileInfo extendedFinderFlags to see if kExtendedFlagObjectIsBusy is set.

  4. 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.

like image 689
Michael Tsai Avatar asked Jan 14 '09 20:01

Michael Tsai


People also ask

What does a red dot mean in Finder?

However, in recent years, zero magnification finders that project an apparent target or small red dot on the night sky have become very common. These are known as 'red dot finders' and they have the advantages of producing their own illumination and being intuitive to use." Advertisement.

How can I tell what process is using a file Mac?

Using the lsof command, we can find out exactly what process or application is using a specified file at that given moment.

How do you show hidden files on Mac?

Showing hidden files via Mac FinderPress the “Command” + “Shift” + “.” (period) keys at the same time. The hidden files will show up as translucent in the folder. If you want to obscure the files again, press the same “Command” + “Shift” + “.” (period) combination.


2 Answers

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.

like image 175
bdrister Avatar answered Oct 04 '22 04:10

bdrister


File business

In Mac OS X v10.4 and later:

  • NSFileBusy.

Finder and data integrity

Whilst Finder progresses a copy of a file (not afterwards) the copy has:

  • HFS type code brok
  • HFS creator code MACS

— together, those two things signify file business.

MACS is the ID of Finder.

If the copy is to a file system without support for attributes such as those

Whilst Finder progresses a copy of a file (not afterwards) the copy has a counterpart:

  • a dot underscore ._ file that includes the necessary extended attribute (xattr).

Related

Why are dot underscore ._ files created, and how can I avoid them? — Ask Different

Finder compatibility with a broad range of file systems and operating systems

If a copy using Finder is interrupted ungracefully, then the presence of brok MACS should ensure that breakage/business is recognisable to:

  • all versions of OS X
  • all versions of Mac OS X
  • Mac OS 9 and some earlier classic versions of the operating system.

Example

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 ..

After using Finder to begin the copy, before completion

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

After Finder successfully completes the copy

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
like image 37
Graham Perrin Avatar answered Oct 04 '22 04:10

Graham Perrin