Basic Examples of SH_COMMAND_REMOVECOMPONENTS
 


Example 1:    Remove all children from node "/Joe" whose names begin with the letter "X".

    BMessage msg(SH_COMMAND_REMOVECOMPONENTS);
    msg.AddString(SH_NAME_TO, "/Joe");
    msg.AddString(SH_NAME_CHILDREN, "X*");
    root->PostMessage(&msg);

Note:  Another way to do this is to send an SH_COMMAND_QUIT BMessage to the child nodes themselves:



Example 2:    Remove all symlinks that originate from node "/Joe".

    BMessage msg(SH_COMMAND_REMOVECOMPONENTS);
    msg.AddString(SH_NAME_TO, "/Joe");
    msg.AddString(SH_NAME_SYMLINKS, "*");
    root->PostMessage(&msg);

Note:  The SH_NAME_SYMLINKS field will cause only children that are symlinks to be removed.  It will never affect "real" children.  However, the SH_NAME_CHILDREN field will cause symlinks to be removed, if the symlinks' names match the specified regular expression string(s).



Example 3:    Remove files "file1" and "file2" from "/Joe"'s disk, using SH_NAME_FILES.

    BMessage msg(SH_COMMAND_REMOVECOMPONENTS);
    msg.AddString(SH_NAME_TO, "/Joe");
    SHNodeSpec filesToDelete;
    filesToDelete.AddFlavor(SHFlavor("file1", 0, 0, 0, false));  // specify all args manually so that AddFlavor() will
    filesToDelete.AddFlavor(SHFlavor("file2", 0, 0, 0, false));  // succeed even if the files don't exist on the sending node.
    msg.AddFlat(SH_NAME_FILES, &multiFiles);
    root->PostMessage(&msg);
 



Example 4:    Remove SHWorkers whose names start with the phrase "RemoveMe", and the SHSorter named "DeadFred", from node "/Joe".

    BMessage msg(SH_COMMAND_REMOVECOMPONENTS);
    msg.AddString(SH_NAME_TO, "/Joe");
    msg.AddString(SH_NAME_WORKERS, "RemoveMe*");
    msg.AddString(SH_NAME_SORTERS, "DeadFred");
    root->PostMessage(&msg);


Fancy Examples of SH_COMMAND_REMOVECOMPONENTS
 



Example 5:    Remove all children, symlinks, and workers, and sorters from "/Joe":

    BMessage msg(SH_COMMAND_REMOVECOMPONENTS);
    msg.AddString(SH_NAME_TO, "/Joe");
    msg.AddString(SH_NAME_WORKERS, "*");  // Removes all SHWorkers
    msg.AddString(SH_NAME_SORTERS, "*");  // Removes all SHSorters (except the default SHWi1dPathSorter)
    msg.AddString(SH_NAME_CHILDREN, "*"); // This will remove all symlinks also!
    root->PostMessage(&msg);

(Actually, this won't remove the SHWi1dPathSorter that the node was given on startup--that sorter is protected from removal, because the SockHop server uses it for internal operations)