func fsGetData(log *logging.Logger, section *common.Section, cfg *ini.File) { var previous int var res common.JSONFile var db database.DB if section.Dataset-1 == 0 { previous = cfg.Section("dataset").Key(section.Grace).MustInt() } else { previous = section.Dataset - 1 } db.Open(log, cfg) defer db.Close() for _, item := range []string{"directory", "file", "symlink"} { for res = range database.ListItems(log, &db, section, item) { switch item { case "directory": fsSaveData(log, cfg, section, res, false) case "symlink": fsSaveData(log, cfg, section, res, false) case "file": if database.ItemExist(log, &db, &res, section, previous) { fsSaveData(log, cfg, section, res, true) } else { fsSaveData(log, cfg, section, res, false) } } } } }
func FileRestore(log *logging.Logger, section *common.Section, cfg *ini.File) { var cmd common.JSONMessage var res common.JSONFile var db database.DB var err error db.Open(log, cfg) defer db.Close() cmd.Context = "file" cmd.Command.Name = "put" if cfg.Section(section.Name).Key("path").String() == "" { log.Debug("About to full restore") cmd.Command.ACL = cfg.Section(section.Name).Key("acl").MustBool() for _, item := range []string{"directory", "file", "symlink"} { for res = range database.ListItems(log, &db, section, item) { if cmd.Command.ACL { log.Debug("About to restore ACLs for " + res.Name) res.Acl, err = database.GetAcls(log, &db, res.Name, section) if err != nil { log.Error("ACLs extraction error for " + res.Name) log.Debug("error: " + err.Error()) } } cmd.Command.Element = res put(log, section, cfg, &cmd) } } } else { log.Debug("About to restore path " + cfg.Section(section.Name).Key("path").String()) cmd.Command.Element, err = database.GetItem(log, &db, cfg.Section(section.Name).Key("path").String(), section) if err != nil { log.Error("Error when putting data to section " + section.Name) log.Debug("error: " + err.Error()) } else { cmd.Command.ACL = cfg.Section(section.Name).Key("acl").MustBool() put(log, section, cfg, &cmd) } } }