Skip to content
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

[Config Save] Error happens when saving a file with quotation marks in its filename #2361

Closed
wants to merge 0 commits into from

Conversation

rayxhuangEC
Copy link

@rayxhuangEC rayxhuangEC commented Sep 8, 2022

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)

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 8, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@rayxhuangEC rayxhuangEC changed the title [Config Save] Error happen when config save a filename with quotation… [Config Save] Error happens when saving a config file with quotation marks in its filename Jan 4, 2023
@rayxhuangEC rayxhuangEC changed the title [Config Save] Error happens when saving a config file with quotation marks in its filename [Config Save] Error happens when saving a file with quotation marks in its filename Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant