Skip to content

Commit c29c00f

Browse files
feat: When creating files/folders, use the parent directory's user an… (#8419)
Refs #6332
1 parent 66aeb38 commit c29c00f

20 files changed

Lines changed: 71 additions & 37 deletions

File tree

agent/app/service/file.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,25 @@ func (f *FileService) Create(op request.FileCreate) error {
204204
}
205205
}
206206
if op.IsDir {
207-
return fo.CreateDirWithMode(op.Path, fs.FileMode(mode))
207+
if err := fo.CreateDirWithMode(op.Path, fs.FileMode(mode)); err != nil {
208+
return err
209+
}
210+
handleDefaultOwn(op.Path)
211+
return nil
208212
}
209213
if op.IsLink {
210214
if !fo.Stat(op.LinkPath) {
211215
return buserr.New("ErrLinkPathNotFound")
212216
}
213-
return fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink)
217+
if err := fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink); err != nil {
218+
return err
219+
}
220+
}
221+
if err := fo.CreateFileWithMode(op.Path, fs.FileMode(mode)); err != nil {
222+
return err
214223
}
215-
return fo.CreateFileWithMode(op.Path, fs.FileMode(mode))
224+
handleDefaultOwn(op.Path)
225+
return nil
216226
}
217227

218228
func (f *FileService) Delete(op request.FileDelete) error {

agent/app/service/website_utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strconv"
1212
"strings"
13+
"syscall"
1314
"time"
1415

1516
"github.com/1Panel-dev/1Panel/agent/app/repo"
@@ -1357,3 +1358,17 @@ func ConfigAIProxy(website model.Website) error {
13571358
}
13581359
return nil
13591360
}
1361+
1362+
func handleDefaultOwn(dir string) {
1363+
parentDir := path.Dir(dir)
1364+
info, err := os.Stat(parentDir)
1365+
if err != nil {
1366+
return
1367+
}
1368+
stat, ok := info.Sys().(*syscall.Stat_t)
1369+
uid, gid := -1, -1
1370+
if ok {
1371+
uid, gid = int(stat.Uid), int(stat.Gid)
1372+
}
1373+
_ = os.Chown(dir, uid, gid)
1374+
}

core/app/api/v2/backup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (b *BaseApi) RefreshToken(c *gin.Context) {
4747
helper.InternalServer(c, err)
4848
return
4949
}
50-
helper.SuccessWithOutData(c)
50+
helper.Success(c)
5151
}
5252

5353
// @Tags Backup Account
@@ -112,7 +112,7 @@ func (b *BaseApi) DeleteBackup(c *gin.Context) {
112112
helper.InternalServer(c, err)
113113
return
114114
}
115-
helper.SuccessWithOutData(c)
115+
helper.Success(c)
116116
}
117117

118118
// @Tags Backup Account
@@ -134,5 +134,5 @@ func (b *BaseApi) UpdateBackup(c *gin.Context) {
134134
helper.InternalServer(c, err)
135135
return
136136
}
137-
helper.SuccessWithOutData(c)
137+
helper.Success(c)
138138
}

core/app/api/v2/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (b *BaseApi) CreateCommand(c *gin.Context) {
2525
helper.InternalServer(c, err)
2626
return
2727
}
28-
helper.SuccessWithOutData(c)
28+
helper.Success(c)
2929
}
3030

3131
// @Tags Command
@@ -119,7 +119,7 @@ func (b *BaseApi) DeleteCommand(c *gin.Context) {
119119
helper.InternalServer(c, err)
120120
return
121121
}
122-
helper.SuccessWithOutData(c)
122+
helper.Success(c)
123123
}
124124

125125
// @Tags Command
@@ -141,5 +141,5 @@ func (b *BaseApi) UpdateCommand(c *gin.Context) {
141141
helper.InternalServer(c, err)
142142
return
143143
}
144-
helper.SuccessWithOutData(c)
144+
helper.Success(c)
145145
}

core/app/api/v2/group.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (b *BaseApi) CreateGroup(c *gin.Context) {
2525
helper.InternalServer(c, err)
2626
return
2727
}
28-
helper.SuccessWithOutData(c)
28+
helper.Success(c)
2929
}
3030

3131
// @Tags System Group
@@ -47,7 +47,7 @@ func (b *BaseApi) DeleteGroup(c *gin.Context) {
4747
helper.InternalServer(c, err)
4848
return
4949
}
50-
helper.SuccessWithOutData(c)
50+
helper.Success(c)
5151
}
5252

5353
// @Tags System Group
@@ -69,7 +69,7 @@ func (b *BaseApi) UpdateGroup(c *gin.Context) {
6969
helper.InternalServer(c, err)
7070
return
7171
}
72-
helper.SuccessWithOutData(c)
72+
helper.Success(c)
7373
}
7474

7575
// @Tags System Group

core/app/api/v2/helper/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func SuccessWithData(ctx *gin.Context, data interface{}) {
4747
ctx.Abort()
4848
}
4949

50-
func SuccessWithOutData(ctx *gin.Context) {
50+
func Success(ctx *gin.Context) {
5151
res := dto.Response{
5252
Code: http.StatusOK,
5353
Message: "success",

core/app/api/v2/host.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (b *BaseApi) DeleteHost(c *gin.Context) {
153153
helper.InternalServer(c, err)
154154
return
155155
}
156-
helper.SuccessWithOutData(c)
156+
helper.Success(c)
157157
}
158158

159159
// @Tags Host
@@ -244,7 +244,7 @@ func (b *BaseApi) UpdateHostGroup(c *gin.Context) {
244244
helper.InternalServer(c, err)
245245
return
246246
}
247-
helper.SuccessWithOutData(c)
247+
helper.Success(c)
248248
}
249249

250250
// @Tags Host

core/app/api/v2/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ func (b *BaseApi) CleanLogs(c *gin.Context) {
7878
return
7979
}
8080

81-
helper.SuccessWithOutData(c)
81+
helper.Success(c)
8282
}

core/app/api/v2/script_library.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (b *BaseApi) CreateScript(c *gin.Context) {
3636
helper.InternalServer(c, err)
3737
return
3838
}
39-
helper.SuccessWithOutData(c)
39+
helper.Success(c)
4040
}
4141

4242
// @Tags ScriptLibrary
@@ -84,7 +84,7 @@ func (b *BaseApi) DeleteScript(c *gin.Context) {
8484
helper.InternalServer(c, err)
8585
return
8686
}
87-
helper.SuccessWithOutData(c)
87+
helper.Success(c)
8888
}
8989

9090
// @Tags ScriptLibrary
@@ -99,7 +99,7 @@ func (b *BaseApi) SyncScript(c *gin.Context) {
9999
helper.InternalServer(c, err)
100100
return
101101
}
102-
helper.SuccessWithOutData(c)
102+
helper.Success(c)
103103
}
104104

105105
// @Tags ScriptLibrary
@@ -121,7 +121,7 @@ func (b *BaseApi) UpdateScript(c *gin.Context) {
121121
helper.InternalServer(c, err)
122122
return
123123
}
124-
helper.SuccessWithOutData(c)
124+
helper.Success(c)
125125
}
126126

127127
func (b *BaseApi) RunScript(c *gin.Context) {

core/app/api/v2/setting.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (b *BaseApi) GetTerminalSettingInfo(c *gin.Context) {
5454
// @Security Timestamp
5555
// @Router /core/settings/search/available [get]
5656
func (b *BaseApi) GetSystemAvailable(c *gin.Context) {
57-
helper.SuccessWithOutData(c)
57+
helper.Success(c)
5858
}
5959

6060
// @Tags System Setting
@@ -86,7 +86,7 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) {
8686
entranceValue := base64.StdEncoding.EncodeToString([]byte(req.Value))
8787
c.SetCookie("SecurityEntrance", entranceValue, 0, "", "", false, true)
8888
}
89-
helper.SuccessWithOutData(c)
89+
helper.Success(c)
9090
}
9191

9292
// @Tags System Setting
@@ -108,7 +108,7 @@ func (b *BaseApi) UpdateTerminalSetting(c *gin.Context) {
108108
helper.InternalServer(c, err)
109109
return
110110
}
111-
helper.SuccessWithOutData(c)
111+
helper.Success(c)
112112
}
113113

114114
// @Tags System Setting
@@ -139,7 +139,7 @@ func (b *BaseApi) UpdateProxy(c *gin.Context) {
139139
helper.InternalServer(c, err)
140140
return
141141
}
142-
helper.SuccessWithOutData(c)
142+
helper.Success(c)
143143
}
144144

145145
// @Tags System Setting
@@ -161,7 +161,7 @@ func (b *BaseApi) UpdateMenu(c *gin.Context) {
161161
helper.InternalServer(c, err)
162162
return
163163
}
164-
helper.SuccessWithOutData(c)
164+
helper.Success(c)
165165
}
166166

167167
// @Tags System Setting
@@ -183,7 +183,7 @@ func (b *BaseApi) UpdatePassword(c *gin.Context) {
183183
helper.InternalServer(c, err)
184184
return
185185
}
186-
helper.SuccessWithOutData(c)
186+
helper.Success(c)
187187
}
188188

189189
// @Tags System Setting
@@ -205,7 +205,7 @@ func (b *BaseApi) UpdateSSL(c *gin.Context) {
205205
helper.InternalServer(c, err)
206206
return
207207
}
208-
helper.SuccessWithOutData(c)
208+
helper.Success(c)
209209
}
210210

211211
// @Tags System Setting
@@ -274,7 +274,7 @@ func (b *BaseApi) UpdateBindInfo(c *gin.Context) {
274274
helper.InternalServer(c, err)
275275
return
276276
}
277-
helper.SuccessWithOutData(c)
277+
helper.Success(c)
278278
}
279279

280280
// @Tags System Setting
@@ -296,7 +296,7 @@ func (b *BaseApi) UpdatePort(c *gin.Context) {
296296
helper.InternalServer(c, err)
297297
return
298298
}
299-
helper.SuccessWithOutData(c)
299+
helper.Success(c)
300300
}
301301

302302
// @Tags System Setting
@@ -318,7 +318,7 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) {
318318
helper.InternalServer(c, err)
319319
return
320320
}
321-
helper.SuccessWithOutData(c)
321+
helper.Success(c)
322322
}
323323

324324
// @Tags System Setting
@@ -380,7 +380,7 @@ func (b *BaseApi) MFABind(c *gin.Context) {
380380
return
381381
}
382382

383-
helper.SuccessWithOutData(c)
383+
helper.Success(c)
384384
}
385385

386386
func (b *BaseApi) ReloadSSL(c *gin.Context) {
@@ -393,7 +393,7 @@ func (b *BaseApi) ReloadSSL(c *gin.Context) {
393393
helper.InternalServer(c, err)
394394
return
395395
}
396-
helper.SuccessWithOutData(c)
396+
helper.Success(c)
397397
}
398398

399399
// @Tags System Setting
@@ -442,7 +442,7 @@ func (b *BaseApi) UpdateApiConfig(c *gin.Context) {
442442
helper.InternalServer(c, err)
443443
return
444444
}
445-
helper.SuccessWithOutData(c)
445+
helper.Success(c)
446446
}
447447

448448
func checkEntrancePattern(val string) bool {

0 commit comments

Comments
 (0)