diff --git a/docs/virtual-folders.md b/docs/virtual-folders.md index 36093ef3dcc33d1e4be47befa5324ba0ef546982..cfd70c34c92c9df7db5a92d9c70ca763c5faf715 100644 --- a/docs/virtual-folders.md +++ b/docs/virtual-folders.md @@ -16,8 +16,6 @@ For example if the configure folder has configured `/tmp/mapped` or `C:\mapped` The same virtual folder can be shared among users, different folder quota limits for each user are supported. Folder quota limits can also be included inside the user quota but in this case the folder is considered "private" and sharing it with other users will break user quota calculation. -The filesystem paths that you want to expose as virtual folders must exist. - Using the REST API you can: - monitor folders quota usage diff --git a/sftpd/sftpd_test.go b/sftpd/sftpd_test.go index 5aeeed95c050d2e5d54d8d27c5abe082e48cc0e8..c8d5afa62117ecd37146abef9d86bb08321185d2 100644 --- a/sftpd/sftpd_test.go +++ b/sftpd/sftpd_test.go @@ -3117,13 +3117,14 @@ func TestVirtualFolders(t *testing.T) { u.Permissions[path.Join(testDir1, "subdir")] = []string{dataprovider.PermCreateSymlinks, dataprovider.PermUpload, dataprovider.PermDelete} - err := os.MkdirAll(mappedPath, os.ModePerm) - assert.NoError(t, err) user, _, err := httpdtest.AddUser(u, http.StatusCreated) assert.NoError(t, err) client, err := getSftpClient(user, usePubKey) if assert.NoError(t, err) { defer client.Close() + // check virtual folder auto creation + _, err = os.Stat(mappedPath) + assert.NoError(t, err) testFileSize := int64(131072) testFilePath := filepath.Join(homeBasePath, testFileName) err = createTestFile(testFilePath, testFileSize) diff --git a/vfs/osfs.go b/vfs/osfs.go index c34cd0a7b0bf53891f1625b4352df486f1e6d68f..658e14bd0c38bb3f2ad9ad2b002a713855623373 100644 --- a/vfs/osfs.go +++ b/vfs/osfs.go @@ -212,6 +212,14 @@ func (fs *OsFs) CheckRootPath(username string, uid int, gid int) bool { if err != nil { return false } + if _, err = fs.Stat(v.MappedPath); fs.IsNotExist(err) { + err = os.MkdirAll(v.MappedPath, os.ModePerm) + fsLog(fs, logger.LevelDebug, "virtual directory %#v for user %#v does not exist, try to create, mkdir error: %v", + v.MappedPath, username, err) + if err == nil { + SetPathPermissions(fs, fs.rootDir, uid, gid) + } + } } return (err == nil) }