Skip to content

Commit

Permalink
update mkdirall
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingPoeta committed Jan 16, 2025
1 parent aec509f commit 629ae88
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/pysdk/pysdk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_makedir(self):
v.makedirs(path) # Should work
path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
v.makedirs(path)
# self.assertRaises(OSError, v.makedirs, os.curdir)
self.assertRaises(OSError, v.makedirs, os.curdir)
path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
'dir5', 'dir6')
Expand Down
10 changes: 7 additions & 3 deletions pkg/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,18 @@ func (fs *FileSystem) Mkdir(ctx meta.Context, p string, mode uint16, umask uint1
}

func (fs *FileSystem) MkdirAll(ctx meta.Context, p string, mode uint16, umask uint16) (err syscall.Errno) {
return fs.MkdirAll0(ctx, p, mode, umask, true)
}

func (fs *FileSystem) MkdirAll0(ctx meta.Context, p string, mode uint16, umask uint16, existOK bool) (err syscall.Errno) {
err = fs.Mkdir(ctx, p, mode, umask)
if err == syscall.ENOENT {
err = fs.MkdirAll(ctx, parentDir(p), mode, umask)
if err == 0 || err == syscall.EEXIST {
err = fs.MkdirAll0(ctx, parentDir(p), mode, umask, existOK)
if err == 0 {
err = fs.Mkdir(ctx, p, mode, umask)
}
}
if err == syscall.EEXIST {
if existOK && err == syscall.EEXIST {
err = 0
}
return err
Expand Down
2 changes: 1 addition & 1 deletion sdk/java/libjfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ func jfs_mkdir(pid int64, h int64, cpath *C.char, mode uint16, umask uint16) int
}

//export jfs_mkdirAll
func jfs_mkdirAll(pid int64, h int64, cpath *C.char, mode, umask uint16) int32 {
func jfs_mkdirAll(pid int64, h int64, cpath *C.char, mode, umask uint16, existOK bool) int32 {
w := F(h)
if w == nil {
return EINVAL
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/juicefs/juicefs/juicefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def mkdir(self, path, mode=0o777):
"""Create a directory."""
self.lib.jfs_mkdir(c_int64(_tid()), c_int64(self.h), _bin(path), c_uint16(mode&0o777), c_uint16(self.umask))

def makedirs(self, path, mode=0o777):
def makedirs(self, path, mode=0o777, exist_ok=False):
"""Create a directory and all its parent components if they do not exist."""
self.lib.jfs_mkdirAll(c_int64(_tid()), c_int64(self.h), _bin(path), c_uint16(mode&0o777), c_uint16(self.umask))
self.lib.jfs_mkdirAll(c_int64(_tid()), c_int64(self.h), _bin(path), c_uint16(mode&0o777), c_uint16(self.umask), c_bool(exist_ok))

def rmdir(self, path):
"""Remove a directory. The directory must be empty."""
Expand Down

0 comments on commit 629ae88

Please sign in to comment.