Fix : Generate No Files or All Files#23
Conversation
Where we will create all files at once - 1.0.0
|
Hi @cophilot , I tried of solving #20 , in this PR, the approach I followed is fairly straight forward (explained in the PR), but I think is good enough to get the job done. Please go through the approach, if it fits. Also if you want me to include any tests to test this functionality , please let me know, I will include that. |
Hi @RounakJoshi09 Also a test for that would be highly appreciated. If you need any help or more information on this let me know :) |
438ceda to
d717a85
Compare
|
@RounakJoshi09 If you are finished with the implementation, please set the PR back to ready. |
9aee8ed to
f8e8d60
Compare
f8e8d60 to
1dfe384
Compare
|
Hi @cophilot , I have changed the approach , according to which, I am storing all the files to be generated in vector, and when the program confirms that all the files can be generated then I am generating them by iterating through the array. Please check this once and let me know what you think about it. |
src/commands/generate.rs
Outdated
| force, | ||
| &mut files_to_create, | ||
| ) { | ||
| for file in files_to_create { |
There was a problem hiding this comment.
This behavior should be handled within the generate_template_dir and similar functions. I would suggest that you do the same behavior within the functions, but you generate the vector within the function that do the checks and if it was successful then generate the files within the function. Here a pseudo example:
fn generate_template_dir(...){
let mut files_to_create: Vec<FileToCreate> = Vec::new();
for f in files{
if canBeAdded -> files_to_create.add(f)
else return false
}
// generate the files from files_to_create
}
|
Thanks @RounakJoshi09 ! It already looks pretty good, only one minor refactoring and then its perfect :) For the test you can edit the If you still have issues creating the test case for this then let me know and I will help you. |
|
Thank you for the feedback, @cophilot . I've implemented the suggested changes. I'd like to provide some context for one of the modifications: To integrate the file generation process within the template handler, I introduced an additional function. This new function initializes the vector for files and subsequently triggers the file generation. The rationale behind this approach is that Please let me know if you need any further clarification or have additional suggestions. |
|
Hi @RounakJoshi09 Thank you for the fix. I will merge it now and the fix will be released with version 2.0.1 :) |
|
Thanks a lot @cophilot . Can you please assign some new task as well |
Replace the
...with your own content!Type of change
Description
Previously, an issue occurred when generating files from a template. If the generation process failed for any reason, users were left with an inconsistent state, where some files were generated while others were not. I have resolved this issue by implementing a tracking system that monitors all created files during the generation process. If the process fails midway, all generated files will be removed, ensuring the state remains consistent and as it was before the process started, thereby preventing any inconsistency.
Changes
I created a vector of tuples that contain information about the path of each file or directory created, as well as a flag indicating whether it is a directory. If the generation process fails, the system will iterate through the created paths, check their existence, and remove them based on whether they are directories or files. This ensures that the state remains consistent and free from partial generation artifacts.