]> www.infradead.org Git - users/hch/nvmetcli.git/commitdiff
nvmetcli: create json file's dir first if it doesn't exist
authorYi Zhang <yizhan@redhat.com>
Wed, 12 Apr 2017 11:34:28 +0000 (19:34 +0800)
committerChristoph Hellwig <hch@lst.de>
Tue, 18 Apr 2017 08:02:53 +0000 (10:02 +0200)
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@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
nvmet/nvme.py

index 3316cabbf6b8e09c05c0c69e2e5dd41d2004b10d..c245a4240dd956f52f775f103a7e298aa4b63a7c 100644 (file)
@@ -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))