On Nov 15, 2010, at 4:01 AM, Leo wrote:

> I wonder if it's possible to detect a shared folder? That is a folder that
> is shared via File Sharing.

It would seem to be possible, since the Finder puts a banner in the window for 
shared folders.

> Am I missing something obvious?

Not obvious, no.

> I couldn't find an appropriate folder attribute in either Cocoa or
> AppleScript. Or any other way to distinguish a shared folder from other
> folders.

There are some flags in Carbon File Manager structures about file system items 
that are supposed to indicate the shared status, but they don't seem to be 
supported any longer.  I used Apple's FSMegaInfo to dump the info, as in:

/path/to/FSMegaInfo -vvv FSGetCatalogInfo -kFSCatInfoGettableInfo <path>


> I also assume there must be a list of all shared folders in one of the Unix
> special directories. Or a way to retrieve it with a shell command. I did
> some extensive research, couldn't find anything.

I doubt there's one single list.  It depends on the specific sharing protocol 
and the configuration of the server for that protocol.  I found that 
/etc/smb.conf includes /var/db/samba/smb.shares, and that file lists the shares 
in a manner which matches the settings in the Sharing preference pane.  
However, that would probably not apply if you don't share via SMB and only 
share via AFP.

Hmm.  I went hunting for the AFP configuration and think I did find the master 
list.  Try this command:

dscl /Local/Default -list SharePoints

Then, take one of the listed share points and do these on it:

dscl /Local/Default -read SharePoints/<share point name>
dscl /Local/Default -read SharePoints/<share point name> directory_path

Be sure to quote the share point name if it contains spaces or other characters 
that the shell will interpret.  Since the "dscl" command is just a front-end to 
Directory Services, there should be a way to do this directly via those APIs.

Some experimentation shows that these records are not modified as you enable 
and disable file sharing protocols or even all of file sharing.  So, you'd have 
to test if file sharing is even enabled before paying attention to them.  I 
believe that toggling file sharing servers on or off amounts to enabling and 
disabling the corresponding service in launchd.  So, I think you may be able to 
query their status with SMJobCopyDictionary() and the relevant identifier (e.g. 
com.apple.AppleFileServer or org.samba.smbd).

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to