ansys / ansys-tools-filetransfer

Python Client for the Ansys Filetransfer Tool
https://filetransfer.tools.docs.pyansys.com/
MIT License
0 stars 0 forks source link

Add a `file_exists` API / method #94

Open greschd opened 6 months ago

greschd commented 6 months ago

📝 Description of the feature

Add a method to check for existence of a file on the remote. Requested by @hpohekar / PyFluent.

💡 Steps for implementing the feature

🔗 Useful links and references

No response

hpohekar commented 6 months ago

@greschd

Is it possible to add delete_file() method that will delete file on the remote.

So that we can use following logic.

fts = RemoteFileTransferStrategy()

if fts.file_exists(file_name):
    fts.delete_file(file_name)
    fts.upload_file(file_name, remote_file_name)
greschd commented 6 months ago

While I see the use of both file_exists and delete_file, it's also worth pointing out that

    fts.delete_file(file_name)
    fts.upload_file(file_name, remote_file_name)

is equivalent to just

    fts.upload_file(file_name, remote_file_name)

In the case we looked at (source and remote file being accidentally the same via a bind-mount), the delete_file would also delete the source file, causing upload_file to fail.

hpohekar commented 6 months ago

Yes, right. I agree.