Skip to contentSkip to conversation

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

PATCH New Yi Zhang 2 participants 2 messages Apr 12, 2017 – Apr 18, 2017 NVMe

lore
Share & tools
lore

Yi Zhang

author
#0 lore raw

PATCH 1/1 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 Yi Zhang <yizhan at redhat.com>
---
 nvmet/nvme.py | 5 +++++
 1 file changed, 5 insertions(+)
nvmet/nvme.py +5 -0
index 3316cab..c245a42 100644
@@ -290,6 +290,11 @@ class Root(CFSNode):
         else:
             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:
             os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR)
             f.write(json.dumps(self.dump(), sort_keys=True, indent=2))
Signature · 1 line
2.9.3
#1 lore raw

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

Thanks a lot,

applied.