Issues with file deleting using scripts

Hello
Could you please help me with one issue? Since few days I can't delete certain files from Gateway directory by script (E:\Program Files\Inductive Automation\Ignition\webserver\webapps\main\someDirectory....). It used to work fine for few weeks, now I can see unlink OSError in the log.

I thought I will fix it based on past topics from this forum, but looks like I didn't found a root cause.

I was reviewing these topics:

looking for some help. Originally I was executing this code to save a picture using script:

...
import os
...
myFile = open(path, 'wb')
myFile.write(f.read())
myFile.close()

and then in another script I was deleting this file by:

os.remove(item)

Since few days I see this in a log:

Caused by: org.python.core.PyException: OSError: unlink(): an unknown error occurred: E:\Program Files\Inductive Automation\Ignition\webserver\webapps\main\RR_crates\PLD2\2024-01-25-09-38-16_12345678900987654_cam1.jpg
... 39 common frames omitted
Caused by: java.nio.file.AccessDeniedException: E:\Program Files\Inductive Automation\Ignition\webserver\webapps\main\RR_crates\PLD2\2024-01-25-09-38-16_12345678900987654_cam1.jpg
at java.base/sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
at java.base/java.nio.file.Files.deleteIfExists(Unknown Source)
at org.python.modules.posix.PosixModule.unlink(PosixModule.java:1119)

After reading topics mentioned above I thought migrating to java.io.File and java.nio.file.Files will fix it and it will work fine, but I get the same error as before ;(

Where should I look for a solution in a code?

Now I have this for saving:

			myFile = File(path)
			myPath = myFile.toPath()			
			Files.write(myPath, f.read())

and deleting:

pattern=rE:\ProgramFiles\InductiveAutomation\Ignition\webserver\webapps\main\RR_crates\PLD2\*.jpg
for item in glob.iglob(pattern):
    someFile = File(item)
    someFile.delete()

It works (deleting) only for files created from other source than Ignition. All files created using this script are blocked by java.exe when trying to delete it from Windows Explorer:

unlink

I assume same process blocks deletion when Ignition executes my script, but I don't know how avoid this scenario in a future.

I would be thankful for any suggestions, thank you, regards, Gregory

Let me know please what else I can paste here - this is my first post here:)

In using Ignition 8.1.36 version, recently updated, before we had 8.1.23 (as far as I remember).

1 Like

It is unfixable. Once the gateway serves one of the files in that webserver folder to a web client, it never lets it go. (Until you restart the gateway.) Placing files in that folder to serve them to clients is not supported, and basically works "accidentally". To properly and reliably serve arbitrary files from your gateway, use the WebDev module. Full stop.

If you have the option to put files into a database as BLOBs, you might be able to use my free Blob Server module to offer such dynamic content.

1 Like

Thanks for fast response, just from curiosity - I was able to delete these files working in previous gateway version, is this something new in 8.1.36?
What would be a suggested way of handling files like these? I need them just for few seconds/minutes (to show them as images in a perspective view), then they are pushed to azure blob storage and can be deleted from gateway server.

It's probably an incidental change from either a Jetty upgrade or the Java upgrade we did between the two versions.
As Phil said, it's unsupported, so we don't test for it.

If you go through the forums, I think I remember someone posting some snippet of web.xml configuration that was supposed to help with the file locks on Windows. @bkarabinchak.psi, my brain is associating it with you, so apologies if this is a false memory and false ping.

Phil is CORRECT.
Unsupported.
False (e.g "accidental") functionality during development and / or will not reliably continue to function...pending on several environmental and operational factors.
Full Stop.

WebDev may work for a lot of simple interactions (1).

Java and / or C (variant) may be required for advanced interactions (1).

(NOTE 1: The term "interactions" is used to describe the file operations that will be applied when the file is processed outside the IGN environment to when it is again accessed by the IGN environment.)

Your mileage may very ... Test Early, Test Often!

I just checked my own history and don't necessarily see anything there.

I do recall having issues with mapped drives in general and moving to using batch files to do anything related to them - mapping/unmapping as needed. I do see this person is using an E drive and maybe that's an additional issue though seems like this is unsupported anyways.

1 Like

I think this is the post I was thinking of. Ignition webserver question - #5 by Sanderd17
Not sure why my brain linked it to you.