| 264 | } |
| 265 | |
| 266 | func writeTrashInfo(dstPath string, info trashInfo) error { |
| 267 | cfg := ini.Empty() |
| 268 | section, err := cfg.NewSection(trashInfoSection) |
| 269 | if err != nil { |
| 270 | return err |
| 271 | } |
| 272 | if _, err := section.NewKey("Path", url.PathEscape(info.Path)); err != nil { |
| 273 | return err |
| 274 | } |
| 275 | if _, err := section.NewKey("DeletionDate", info.DeletionDate.Format(trashInfoTimeLayout)); err != nil { |
| 276 | return err |
| 277 | } |
| 278 | if _, err := section.NewKey("Size", strconv.FormatInt(info.Size, 10)); err != nil { |
| 279 | return err |
| 280 | } |
| 281 | if _, err := section.NewKey("IsDir", strconv.FormatBool(info.IsDir)); err != nil { |
| 282 | return err |
| 283 | } |
| 284 | |
| 285 | var buf bytes.Buffer |
| 286 | if _, err := cfg.WriteTo(&buf); err != nil { |
| 287 | return err |
| 288 | } |
| 289 | tmp := dstPath + ".tmp" |
| 290 | if err := os.WriteFile(tmp, buf.Bytes(), constant.FilePerm); err != nil { |
| 291 | return err |
| 292 | } |
| 293 | return os.Rename(tmp, dstPath) |
| 294 | } |
| 295 | |
| 296 | func readTrashInfo(srcPath string) (*trashInfo, error) { |
| 297 | cfg, err := ini.Load(srcPath) |