CARTAvis / carta-frontend

Source code repository for the frontend component of CARTA, a new visualization tool designed for the ALMA, the VLA and the SKA pathfinders.
https://cartavis.github.io/
GNU General Public License v3.0
20 stars 10 forks source link

SaveFile bug removes/overwrites directory #2384

Open pford opened 6 months ago

pford commented 6 months ago

Describe the bug As reported by @kswang1029 and described in carta-backend #1377:

If we save an image without giving a filename in the file browser dialog and click the save button, there will be an error toast showing the target saving directory not found. But then the original target directory is actually gone. This is a critical bug as user data will be lost.

We can also currently overwrite any directory, file, or image by typing in the path as the name of the file to save. The backend overwrites the path in the SaveFile message unless it is the source image path, assuming the frontend has confirmed the overwrite with the "overwrite?" dialog. The frontend only shows this dialog when the path is an image in the current file list.

To Reproduce TEST WITH CAUTION!

Steps to reproduce the behavior:

  1. create a test directory call "test_save_image" somewhere in the directory tree (eg ~/carta_image_pool/test_save_image)
  2. load an image
  3. use the save image dialog to save it with a filename in ~/carta_image_pool/test_save_image. This should be successful and we do see a new file is created in the target directory.
  4. now use the save image dialog to save it once again but with giving a filename (ie empty filename). Then we will see an error toast and if we check the existence of ~/carta_image_pool/test_save_image, it is gone!
  5. type in the name of a directory in the current file list. The directory is overwritten with the image!

Expected behavior We should apply these fixes:

  1. If the target filename is blank, disable the save button
  2. When the user confirms the image overwrite, set new SaveFile overwrite field to true. protobuf PR #97 (branch: save_file_overwrite).

In the backend, SaveFile fails when:

These are error conditions where the image will not be saved, regardless of the overwrite flag. Show error message to user.

In this case, frontend did not detect that the path is an image (or user bypassed the frontend with scripting), so we need user confirmation to overwrite. Frontend should pop up dialog, if ok then send SaveFile with overwrite=true.

Backend PR #1378 (branch: pam/1377_save_image)

This fix should also be backported to the last release.

Platform info (please complete the following information):