Skip to content
Snippets Groups Projects
Commit 85bf98b8 authored by Yi Zhang's avatar Yi Zhang Committed by Christoph Hellwig
Browse files

nvmetcli: create json file's dir first if it doesn't exist


The saveconfig operation will be failed as the /etc/nvmet dir
doesn't exist by default, so create it first before save operation.

$ ./nvmetcli
/> saveconfig
[Errno 2] No such file or directory: '/etc/nvmet/config.json.temp'

Signed-off-by: default avatarYi Zhang <yizhan@redhat.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 9ab2ac6c
No related branches found
No related tags found
No related merge requests found
...@@ -290,6 +290,11 @@ class Root(CFSNode): ...@@ -290,6 +290,11 @@ class Root(CFSNode):
else: else:
savefile = DEFAULT_SAVE_FILE savefile = DEFAULT_SAVE_FILE
savefile_abspath = os.path.abspath(savefile)
savefile_dir = os.path.dirname(savefile_abspath)
if not os.path.exists(savefile_dir):
os.makedirs(savefile_dir)
with open(savefile + ".temp", "w+") as f: with open(savefile + ".temp", "w+") as f:
os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR) os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR)
f.write(json.dumps(self.dump(), sort_keys=True, indent=2)) f.write(json.dumps(self.dump(), sort_keys=True, indent=2))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment