spine-tools / Spine-Toolbox

Spine Toolbox is an open source Python package to manage data, scenarios and workflows for modelling and simulation. You can have your local workflow, but work as a team through version control and SQL databases.
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
73 stars 18 forks source link

File -> Save Project As... overwrites files without warning in a very specific case #441

Open spine-o-bot opened 3 years ago

spine-o-bot commented 3 years ago

In GitLab by @PekkaSavolainen on Jan 24, 2020, 14:44

There is a situation when saving the project to a new directory with File->Save Project As... overwrites user's files without prompt.

Consider the following directory structure, where directory SpineToolboxProjects contains three Spine Toolbox projects (my_spinetoolbox_project, another_spinetoolbox_project and input_data).

SpineToolboxProjects/
|  my_spinetoolbox_project/
|  + .spinetoolbox/
|    + project.json
|    + items/
|      + dataconn1/
|      ...
|  + input_data/  # User created folder for any data files etc.
|    + my_source_data.csv
|    ...
|  another_spinetoolbox_project/
|  + .spinetoolbox/
|    + project.json
|    + items/
|      ...
|  input_data/
|  + .spinetoolbox/
|    + project.json
|    + items/
|      data_store1/
|      ...
|  + my_source_data.csv

There are three cases to consider with the Save Project As... option:

  1. If user selects Save Project As into an empty directory, everything is fine.
  2. If user chooses a directory that already contains the .spinetoolbox/ directory, the app notices this and asks if overwrite is Ok. After selecting Overwrite, all duplicate files will be overwritten. Any extra files will not be deleted. For example, if the project that is overwritten contained some project item that the replacing project does not have, these extra files will remain in the new project as well.
  3. The tricky part. What if the user chooses the SpineToolboxProjects directory in Save Project As.... In this case, the app notices that the directory is not empty and asks if you want to make this directory into a Spine Toolbox project directory. If user chooses to continue, the following happens. The input_data Spine Toolbox project will become an internal directory of the SpineToolboxProjects directory. my_source_data.csv file will be overwritten. input_data project would still be a valid Spine Toolbox project though.

Even though, the third case seems a bit theoretical, I think people need to be made aware of this since, we can now make any directory a Spine Toolbox project.

The proposed solution for this is to show the user the files that will be overwritten beforehand.

spine-o-bot commented 3 years ago

In GitLab by @manuelma on Jan 24, 2020, 15:19

What is my_source_data.csv overwritten with? Does the project being saved have a file with that exact name?

spine-o-bot commented 3 years ago

In GitLab by @PekkaSavolainen on Jan 24, 2020, 15:24

It is overwritten by my_source_data.csv in the project that is in directory my_spinetoolbox_project. And yes, it has to be exact same name for this to happen.

And there has to be a user created data folder in SpineToolboxProjects/my_spinetoolbox_project/input_data that must match exactly another project that is in directory SpineToolboxProjects/input_data.

spine-o-bot commented 3 years ago

In GitLab by @manuelma on Jan 24, 2020, 15:28

I think I get. So case 3 is saving my_spinetoolbox_project into SpineToolboxProjects, right?

spine-o-bot commented 3 years ago

In GitLab by @PekkaSavolainen on Jan 24, 2020, 15:29

yes