-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small refactoring CR23 - File deletion #1732
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,12 @@ class MyStudyFinder final : public Data::StudyFinder | |
study->parameters.readonly = true; | ||
|
||
logs.info() << "Saving..."; | ||
study->saveToFolder(folder); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally, we should add this to the src/libs/antares/study/cleaner/cleaner.cpp, which is supposed to clean any study from unsuitable files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. I've looked up cleaner.cpp file in details, and apparently after upgrading and saving our new files, we will delete deprecated files with clean command, so I don't think that we need automatic deletion after upgrade. With that been said, this PR shouldn't be merged and code for deletion of files should be excluded. |
||
uint tempVersionVar = (uint)study->header.version; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tempVersionVar : we should be more clear. This variable is the current study version, isn't it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An answer to the previous comment from @nikolaredstork was given here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is what think, eventually about tempVersionVar and this added piece of code. ...
bool isSaved = study->saveToFolder(folder);
if (isSaved)
deleteDeprecatedHydroMaxPowerTSFiles(study->areas,
study->folderInput.to<std::string>,
study->header.version); Note we don't need the source (what you called tmp) study version here. It's more simple like this, don't you think ? |
||
bool isSaved = study->saveToFolder(folder); | ||
|
||
if (isSaved && (tempVersionVar != Antares::Data::versionLatest)) | ||
study->deleteDeprecatedFiles(tempVersionVar); | ||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,7 +393,11 @@ class JobSaveStudy final : public Toolbox::Jobs::Job | |
} // save as | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guilpier-code This is obviously code duplication. Do you have proposal where potential function should be defined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As you know, we don't want to enhance the UI code, we think it's not worth it. |
||
// Save the study (only changes in the most cases) | ||
study->saveToFolder(pFolder); | ||
uint tempVersionVar = study->header.version; | ||
bool isSaved = study->saveToFolder(pFolder); | ||
|
||
if (isSaved && (tempVersionVar != Antares::Data::versionLatest)) | ||
study->deleteDeprecatedFiles(tempVersionVar); | ||
|
||
// Scenario Builder | ||
if (pCanReleaseScenarioBuilder && study->scenarioRules) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class Study is large enough, we plan to split it in many pieces, and we don't want it to grow.
It could be something like :
On the client side, it would be :
removeDeprecatedHydroMaxPowerTSfiles(study.areas, study.folderInput.to<std::string>, study.header.version),
Note : about
removeFile(filePath)
, it probably already exists in the unit tests code areaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to first read currentStudyVerstion and save it value to temporary variable, after that we are calling
study->saveToFolder
. Why we need temporary variable? We need it because, if we are upgrading a study, variablestudy->.header.version
will be changed (afterstudy->saveToFolder
function call) to a current version of our software, and if we are passing value of thestudy->.header.version
variable to thedeleteDeprecatedHydroMaxPowerTSFiles
function we will be passing already updated value of our study version (currently 870). If we are upgrading for example from 8.2 version than we need to pass 820 value to thedeleteDeprecatedHydroMaxPowerTSFiles
function, and we are doing that via temporary variable.Condition
if (currentStudyVersion >= 870)
must be changed toif(previousVersion < 870)
. Why? Because currentStudyVersion after saving a study will have 870 value, and deletion won't be performed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need to delete files just if
study->saveToFolder()
function call return true, than we are sure that our new files are saved and all data from deprecated files are stored in our new files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Your last comments regard more the updater/main.cpp than the src/libs/antares/study/study.h.
So I answer you in updater/main.cpp (below)