MCPcopy Index your code
hub / github.com/1Panel-dev/1Panel / Update

Method Update

agent/app/service/ftp.go:188–249  ·  view source on GitHub ↗
(req dto.FtpUpdate)

Source from the content-addressed store, hash-verified

186}
187
188func (f *FtpService) Update(req dto.FtpUpdate) error {
189 if _, err := os.Stat(req.Path); err != nil {
190 if os.IsNotExist(err) {
191 if err := os.MkdirAll(req.Path, os.ModePerm); err != nil {
192 return err
193 }
194 } else {
195 return err
196 }
197 }
198
199 pass, err := encrypt.StringEncrypt(req.Password)
200 if err != nil {
201 return err
202 }
203 ftpItem, _ := ftpRepo.Get(repo.WithByID(req.ID))
204 if ftpItem.ID == 0 {
205 return buserr.New("ErrRecordNotFound")
206 }
207 passItem, err := encrypt.StringDecrypt(ftpItem.Password)
208 if err != nil {
209 return err
210 }
211
212 client, err := toolbox.NewFtpClient()
213 if err != nil {
214 return err
215 }
216 needReload := false
217 updates := make(map[string]interface{})
218 if req.Password != passItem {
219 if err := client.SetPasswd(ftpItem.User, req.Password); err != nil {
220 return err
221 }
222 updates["password"] = pass
223 needReload = true
224 }
225 if req.Status != ftpItem.Status {
226 if err := client.SetStatus(ftpItem.User, req.Status); err != nil {
227 return err
228 }
229 updates["status"] = req.Status
230 needReload = true
231 }
232 if req.Path != ftpItem.Path {
233 if err := client.SetPath(ftpItem.User, req.Path); err != nil {
234 return err
235 }
236 updates["path"] = req.Path
237 needReload = true
238 }
239 if req.Description != ftpItem.Description {
240 updates["description"] = req.Description
241 }
242 if needReload {
243 _ = client.Reload()
244 }
245 if len(updates) != 0 {

Callers

nothing calls this directly

Calls 9

SetPasswdMethod · 0.95
ReloadMethod · 0.95
MkdirAllMethod · 0.80
SetStatusMethod · 0.80
SetPathMethod · 0.80
GetMethod · 0.65
WithByIDMethod · 0.65
UpdateMethod · 0.65
StatMethod · 0.45

Tested by

no test coverage detected