It seems in Tiger that they have take out FSTAT. I am trying to use LSOF but I am having a little trouble. Basically I need to copy files from a server to a client machine while users might be copying to that same file or directory. When I do an LSOF it seem to only work in the top level of the system. When i change the directory it still scans the whole system. And if I do lsof /my/path it doesn’t scan anything. Does lsof always scan the kernel memory? Is it possible just to scan one directory?
LSOF has many, many options that I don’t even begin to understand. That said, this works for me for returning an alias list of open files in a given directory (using the “+D” option of LSOF) on Mac OS X 10.4.1:
my get_open_files(choose folder)
on get_open_files(source_folder)
try
set the_files to (do shell script "lsof -F n +D " & (quoted form of POSIX path of source_folder))
on error the_error
if the_error = "An error of type 1 has occurred." then
set the_files to "No open files."
else
set the_files to the_error
end if
end try
if (count the_files's paragraphs) > 1 then
set the_files to paragraphs 2 thru -1 of the_files
set alias_files to {}
repeat with i from 1 to (count the_files)
try
set end of alias_files to ((((item i of the_files)'s text 2 thru -1) as POSIX file) as alias)
end try
end repeat
end if
return alias_files
end get_open_files
I’ve read elsewhere that a file’s open status is not necessarily a reliable indication of whether it’s available for another operation, particularly if that file is being written over a network. The gist was that an application (perhaps Quark, for example) might open-write-close, open-write-close, repeatedly while writing the file, rather than a simple open - write, write, write - close. Anyone know whether this is the case and, if so, with only some specific apps or more generally?