Delete Folders in /home/dev/unsecured/ with PACControl

Trying to delete all files and subdirectories in /home/dev/unsecured/ OR any subdirectory that’s created when Writing to a File with PACControl.

Yes it can be done with NODE-RED (rm -r /home/dev/unsecured/) but this is an OEM customer and trying to keep everything within PACControl since this will be at multiple locations with possibly different versions of node-red, etc.
Basically PACControl is just cleaner for them.

Currently tried the following
XFER_WRITE_STATUS = SendCommunicationHandleCommand(chXFER_FILE, “delete”);

Able to delete individual files under the subdirectory - com handle setup as follows:
XFER_COM_HANDLE = “file:w,/home/dev/unsecured/PARAMETER/TUNE_F.TXT”;

Tried several variations to delete the directory (in this case PARAMETER) with no success.
I do not get a command status failure (zero) but nothing is deleted.

Any ideas on how to delete the PARAMETER sub-directory or a mass delete under a directory via PACControl would be welcome.

Linux won’t let any old user delete a directory that is not empty. So that option is out.
Mass delete from PAC Control is just not a firmware command (yet). I can add the request, but that option will be off the table until that option is added.

Best thing I can think of is to write a loop that reads the file names and then deletes them by name.

Thanks Ben - will I then be able to delete the directory ?
If so then would the com handle be:
“file:w,/home/dev/unsecured/PARAMETER"

As a follow up - tired several permutations of the previous communication handle but cannot delete the subdirectory.

Never thought of it before but can’t delete the subdirectory through groov Manage either.

Any non NODE_RED or Shell Access way to delete subdirectories ?

Lou,

Sorry, I am a little slammed here to test this before I reply, but did you try the FTP commands?

image

From page 106 of the pac control command reference. Doc 1701.

Thanks Ben,
These commands are a blast from the past. Used to use for internal SNAP files but haven’t done so in years.

I did try with EPIC but no luck.

Not sure if I setup the Communication handle correctly since I get a -447 error (ftp connect failed).
I did setup the EPIC to accept communication on port 21 and 20. However did not reboot the EPIC (did save and everything updated).

Com Handle set as “ftp:127.0.0.1:21,m,m”

Let me know if I screwed up with the com handle.
Would directory structure be the same as EPIC to access (/home/dev/unsecured/) ?

Its one of those problems I know can be done. However if push comes to shove I’ll setup Node Red. Was trying to avoid one more thing that the OEM needs to setup for each system.

The EPIC does not support FTP (we discourage it - but have a guide on how to install it via shell here; Installing and Configuring vsftpd on groov EPIC | Opto 22 Developer) at all, so my thought was to use them with a tcp: com handle… Just in the off chance they would work in that (oddball) way.

Worth a shot. At least now I don’t feel too bad I couldn’t do with FTP.
As I said haven’t used the ftp commands in years (better way to do things now).

The issue was trying to delete directory and files via PACControl.
Any other ideas you may have would be welcome.

Thanks for your help.

Ben, want to revisit the question of directory and how to delete files created by PACControl in regard to the EPIC Controller

I’ve setup the system to delete preset files (verses dynamic names) but still run into an issue with dynamic filenames.
FYI - I tried the several permutations of the rmdir command within PACControl with no luck - if this works can you provide Communication Handle format and Send Communication Handle Command examples - because what I’m trying is giving me an error

Since Files and directories created by PACControl cannot be deleted by Node Red (at least simply):

  • Is there a way to use the PACControl user account in Node Red?

  • SUDO doesn’t work in Node Red or can it ? (I get a lecture that I shouldn’t do this when I try but it doesn’t work)

  • How do you delete directories via Groov Manage ?
    I’ve done it will SSH but this is for an OEM customer and they don’t want their customers having that type of access.

  • Anyway to wild card delete contents of directory in PACControl?

The issue that I have is we are creating files on the drive (via PACControl) and want a means to blow everything away without SSH or Groov Manage access. Node Red was my go to to delete directories but I get locked out until I delete files via PACControl. This works when I know all the filenames but if unknown not sure how to do.

The software engineers have addressed this core issue.
It requires both new EPIC firmware and a new version of PAC Control that has the new comm handle commands.
Both are in QA at the moment. I don’t have a firm release date for those two releases but I know its weeks, not hours if that helps.

Because of the way Linux handles users and security in general, we don’t have any non-shell work arounds.

Thank you for the quick response.
As always - greatly appreciated.

Any update regarding this issue ?
Can PACControl now delete subdirectories ? took a quick look in help but doesn’t seem like this has been setup. Also not setup to test at this time.

Yes. It has been addressed many firmware versions ago (we have had more than 3 since March 2021 off the top of my head).

So if you run the latest controller firmware and the latest PAC Control, the commands are there and they work as expected.

Thanks BUT not working for me. Setup on EPIC using 3.4.0-b.55 (PACControl 10.3 - assume this is good).
Similar to the original issue.

Able to delete individual files:

//////////////////
XFER_COM_HANDLE = "file:w,/home/dev/unsecured/PARAMETER/BSNAME.TXT" ;
SetCommunicationHandleValue(XFER_COM_HANDLE,chXFER_FILE);

XFER_WRITE_OPEN_STATUS = OpenOutgoingCommunication(chXFER_FILE);

IF (IsCommunicationOpen(chXFER_FILE)) THEN
XFER_WRITE_STATUS = SendCommunicationHandleCommand(chXFER_FILE, "delete");
ENDIF
//////////////////

This works and deletes the specified file.

Now trying to delete the PARAMETER subdirectory.
Tried Communication Handles:

  • “file:w,/home/dev/unsecured/PARAMETER/” with delete command and rmdir command - no good with and without the ending “/”

  • “tcp:/home/dev/unsecured/PARAMETER” with delete command and rmdir command - no good with and without the ending “/”

I’m assuming my communication handle structure is wrong OR it doesn’t work. Not getting errors regarding com status.

Please let me know.

I will need to test your situation I think…

Here is how I tested it here;

// Now delete the directory we created; again, only 'file:' is required for a directory-type COM handle
SetCommunicationHandleValue( "file:", chFile );
nResult = OpenOutgoingCommunication( chFile );

// Move up a directory so we can delete the one we're in now
nResult = SendCommunicationHandleCommand( chFile, "cd:.." );
nResult = SendCommunicationHandleCommand( chFile, "cwd:sRcv" );

// Now that we're in its parent directory, we can delete the new one we made
nResult = SendCommunicationHandleCommand( chFile, "rmdir:Test Directory" );
nResult = CloseCommunication( chFile );

Was going to try but before I do needed some clarifications:
Is is this for Unsecured file directory ? This is where I’m putting the files

On your setup “cd:…” goes to which directory on the EPIC ?
And “cwd:sRcv” - change working directory - where / what is sRcv ?

Do I need to use “cwd:/home/dev/unsecured/” ?

So assuming I’m in /home/dev/unsecured/ directory I should be able to use
“rmdir:PARAMETER” to delete this directory.

You have to not be in the directory you are trying to delete.
So I just moved up (out) one directory, the name does not matter.

Here is the test strategy we have been using.
FileDirCmds.B10.3d.Pro.Archive.D12102020.T092701.zip (4.8 KB)

@Beno I’m back on this one, finally had a chance to look at your example and see if I could make it work - IT DIDN’T.
Updated EPIC to latest firmware and using 10.3 (basic on my sample project).

Tried to make a directory as per your logic and received error code -463 (Insufficient Privilege to Perform Option). Tried several permutation and different directories but no good. Was wasting time so figure I’d go back and make sure I’m not missing something.

Going back to my previous comments - and yes I know I had to be out one directory to delete the directory,

I want to to delete via PACControl directories in UNSECURED. This is important so customer has access and we can transfer files to usb, etc.

If all files need to be deleted from within directory prior to removal - is there a wild card delete ?

Is there any documentation on PACControl file manipulation within the EPIC, because I haven’t seen it ?

In past tried to delete directories with Node Red - since Files and directories are created by PACControl they cannot be deleted by Node Red (unless something was changed to allow this).

Per previous post, I’m able to write and delete files (as long as I know the name) via PACControl. Trying to mass delete and remove directories (not using shell) .

Guess I’m asking for the Dummy’s Guide to EPIC File Management using PACControl.
Again using the unsecured directory so please show how we would do in this directory (add directory, remove directory, remove files (without name if possible).

Help is appreciated.

@Lou_Bertha I’ve been working with this as well and hope to help address some things.

I did not get this error with the test strategy @Beno attached above, by stepping through it I can easily create Test Directory, create, write to, and view a file within it, then delete that file and finally delete the test folder all without any issue. Either within or out of the unsecured folder.
What specifically have you tried with different permutations / directories? Were you able to test any other parts of the chart successfully?

In the permutations you tested, did you try running cd:unsecured before mkdir?
That was enough for me to get a new directory in the unsecured file area (and delete it later), which it sounds like that’s what you need.
Rather than show it in groov Manage, here it is through shell so you can see exactly where it is and that the file is in fact there:
image


To the best of my knowledge, no, there is not a wildcard delete. If you check the PAC Control Command Reference it explains the delete ftp command clearly:
image

Here you can see delete removes the file specified by dest, which must be handed a filename – which I interpret to be a singular filename. Trying to use a wildcard like *.* causes an error because it cannot have multiple destinations set to the same comm handle. Because of that, without a specific file it does not know what to open, thus cannot know what to delete, making it impossible to remove files without a name.

If anyone else knows otherwise please let me know!

@torchard Thanks for the insight and help.
I went back and used the Test configuration that @Beno provided to add and delete a directory and it worked!!!
Originally I cut and pasted the commands into an existing configuration (and modified tags), they looked the same, it compiled, but after I had the test config working I went back to test my original setup:

  • I originally asked what was cwd:sRcv - I didn’t realize that sRcv was a string variable since it was part of the command string. You can compile without adding this string variable - this causes the -28 (object not found errors).
  • I did try multiple variations but the missing String kept giving me errors.
  • “cd:/home/dev/unsecured” does work. It wasn’t clear what the default directory was in the example and I tried a multiple variations (some right, most wrong).

A little more details to regarding defaults and what the commands do would have helped BUT I think I’m my own worst enemy - I probably had it working at some point (even with the error because of the missing string variable) but this active configuration had a node red flow setup to delete directories (empty) when the logic was activated. It probably was creating the directory but node red was deleting it right after I created it. Yep always test on a blank canvas.

One last question / comments regarding mass deletes of files created by PACControl.

  • As long as I know the filenames I can delete in PACControl - built into the configuration.
  • Node Red will not allow me to delete files created by PACControl but it will allow me to delete empty directories (as I noted above)
  • I can delete these files using shell access but need to use the sudo command

Is there a way to delete files created by other users, PACControl in Node Red ?
I’ve tried sudo in the node red command lines but it wants me to enter a password (based on debug errors).
Can you run sudo commands in node red to allow these types of deletes?

Thanks again for all the help. Let me know your thoughts on deleting files created by PACControl via Node Red.