[Config Save] Error happens when saving a file with quotation marks in its filename #2361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When running the command sudo config save "\"atlas_config_1x100G\[40G\]\(4\)\"" -y, an error happened.
admin@DUT7:/etc/sonic$ sudo config save "\"atlas_config_1x100G\[40G\]\(4\)\"" -y
Running command: /usr/local/bin/sonic-cfggen -d --print-data > "atlas_config_1x100G\[40G\]\(4\)"
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/config/main.py", line 152, in read_json_file
with open(fileName) as f:
FileNotFoundError: [Errno 2] No such file or directory: '"atlas_config_1x100G\\[40G\\]\\(4\\)"'
What I did
The command "config save" invoke the command "/usr/local/bin/sonic-cfggen -d --print-data" and use the redirection mechanism to gererate a config file. However, in this proccedure, some of the characters will be stripped by the linux shell, e.g. ", ', and \, that it will save a file doesn't same with the original input filename. And after gernerating the config file, it will open the file and arrange the data. The fail happened when it tried to open a file didn't exist. That is because the filename of the file it tried to open doesn't match the file it created.
Fix the command "config save" that it can match the filename it created and it tried to open.
How I did it
Strip the filename by 'echo' command that the filename can conform the linux shell command rule.
How to verify it
Run the command sudo config save "\"atlas_config_1x100G\[40G\]\(4\)\"" -y
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)