storage/filesytem: more consistent logging
This commit is contained in:
parent
a115c50037
commit
cca1d579db
@ -189,19 +189,12 @@ func (b *filesystemBackend) ListCalendars(ctx context.Context) ([]caldav.Calenda
|
|||||||
if err == nil && len(result) == 0 {
|
if err == nil && len(result) == 0 {
|
||||||
// Nothing here yet? Create the default calendar.
|
// Nothing here yet? Create the default calendar.
|
||||||
log.Debug().Msg("no calendars found, creating default calendar")
|
log.Debug().Msg("no calendars found, creating default calendar")
|
||||||
cal, err_ := b.createDefaultCalendar(ctx)
|
cal, err := b.createDefaultCalendar(ctx)
|
||||||
if err_ != nil {
|
if err == nil {
|
||||||
log.Debug().Int("results", len(result)).Bool("success", false).Str("error", err_.Error()).Msg("filesystem.ListCalendars() done")
|
|
||||||
return nil, fmt.Errorf("error creating default calendar: %s", err_.Error())
|
|
||||||
}
|
|
||||||
result = append(result, *cal)
|
result = append(result, *cal)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Warn().Int("results", len(result)).Bool("success", false).Str("error", err.Error()).Msg("filesystem.ListCalendars() done")
|
|
||||||
} else {
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.ListCalendars() done")
|
|
||||||
}
|
}
|
||||||
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.ListCalendars() done")
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,14 +207,14 @@ func (b *filesystemBackend) GetCalendar(ctx context.Context, urlPath string) (*c
|
|||||||
}
|
}
|
||||||
localPath = filepath.Join(localPath, calendarFileName)
|
localPath = filepath.Join(localPath, calendarFileName)
|
||||||
|
|
||||||
log.Debug().Str("local_path", localPath).Msg("loading calendar")
|
log.Debug().Str("path", localPath).Msg("loading calendar")
|
||||||
|
|
||||||
data, readErr := os.ReadFile(localPath)
|
data, err := os.ReadFile(localPath)
|
||||||
if readErr != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(readErr) {
|
if os.IsNotExist(err) {
|
||||||
return nil, webdav.NewHTTPError(404, err)
|
return nil, webdav.NewHTTPError(404, err)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("error opening calendar: %s", readErr.Error())
|
return nil, fmt.Errorf("error opening calendar: %s", err.Error())
|
||||||
}
|
}
|
||||||
var calendar caldav.Calendar
|
var calendar caldav.Calendar
|
||||||
err = json.Unmarshal(data, &calendar)
|
err = json.Unmarshal(data, &calendar)
|
||||||
@ -233,7 +226,7 @@ func (b *filesystemBackend) GetCalendar(ctx context.Context, urlPath string) (*c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) GetCalendarObject(ctx context.Context, objPath string, req *caldav.CalendarCompRequest) (*caldav.CalendarObject, error) {
|
func (b *filesystemBackend) GetCalendarObject(ctx context.Context, objPath string, req *caldav.CalendarCompRequest) (*caldav.CalendarObject, error) {
|
||||||
log.Debug().Str("url_path", objPath).Msg("filesystem.GetCalendarObject()")
|
log.Debug().Str("path", objPath).Msg("filesystem.GetCalendarObject()")
|
||||||
|
|
||||||
localPath, err := b.safeLocalCalDAVPath(ctx, objPath)
|
localPath, err := b.safeLocalCalDAVPath(ctx, objPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -243,7 +236,6 @@ func (b *filesystemBackend) GetCalendarObject(ctx context.Context, objPath strin
|
|||||||
info, err := os.Stat(localPath)
|
info, err := os.Stat(localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
log.Debug().Str("local_path", localPath).Msg("object not found")
|
|
||||||
return nil, webdav.NewHTTPError(404, err)
|
return nil, webdav.NewHTTPError(404, err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -256,7 +248,7 @@ func (b *filesystemBackend) GetCalendarObject(ctx context.Context, objPath strin
|
|||||||
|
|
||||||
calendar, err := calendarFromFile(localPath, propFilter)
|
calendar, err := calendarFromFile(localPath, propFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug().Err(err).Msg("error reading calendar")
|
log.Debug().Str("path", localPath).Err(err).Msg("error reading calendar")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,11 +276,7 @@ func (b *filesystemBackend) ListCalendarObjects(ctx context.Context, urlPath str
|
|||||||
}
|
}
|
||||||
|
|
||||||
result, err := b.loadAllCalendarObjects(ctx, urlPath, propFilter)
|
result, err := b.loadAllCalendarObjects(ctx, urlPath, propFilter)
|
||||||
if err != nil {
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.ListCalendarObjects() done")
|
||||||
log.Warn().Int("results", len(result)).Bool("success", false).Str("error", err.Error()).Msg("filesystem.ListCalendarObjects() done")
|
|
||||||
} else {
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.ListCalendarObjects() done")
|
|
||||||
}
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,24 +289,18 @@ func (b *filesystemBackend) QueryCalendarObjects(ctx context.Context, urlPath st
|
|||||||
}
|
}
|
||||||
|
|
||||||
result, err := b.loadAllCalendarObjects(ctx, urlPath, propFilter)
|
result, err := b.loadAllCalendarObjects(ctx, urlPath, propFilter)
|
||||||
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.QueryCalendarObjects() load done")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Int("results", len(result)).Str("error", err.Error()).Msg("filesystem.QueryCalendarObjects() error loading")
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.QueryCalendarObjects() load done")
|
|
||||||
|
|
||||||
filtered, err := caldav.Filter(query, result)
|
filtered, err := caldav.Filter(query, result)
|
||||||
if err != nil {
|
log.Debug().Int("results", len(filtered)).Err(err).Msg("filesystem.QueryCalendarObjects() filter done")
|
||||||
log.Warn().Int("results", len(result)).Str("error", err.Error()).Msg("filesystem.QueryCalendarObjects() error filtering")
|
return filtered, err
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
log.Debug().Int("results", len(filtered)).Bool("success", true).Msg("filesystem.QueryCalendarObjects() done")
|
|
||||||
return filtered, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath string, calendar *ical.Calendar, opts *caldav.PutCalendarObjectOptions) (loc string, err error) {
|
func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath string, calendar *ical.Calendar, opts *caldav.PutCalendarObjectOptions) (loc string, err error) {
|
||||||
log.Debug().Str("url_path", objPath).Msg("filesystem.PutCalendarObject()")
|
log.Debug().Str("path", objPath).Msg("filesystem.PutCalendarObject()")
|
||||||
|
|
||||||
_, uid, err := caldav.ValidateCalendarObject(calendar)
|
_, uid, err := caldav.ValidateCalendarObject(calendar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -376,7 +358,7 @@ func (b *filesystemBackend) PutCalendarObject(ctx context.Context, objPath strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) DeleteCalendarObject(ctx context.Context, path string) error {
|
func (b *filesystemBackend) DeleteCalendarObject(ctx context.Context, path string) error {
|
||||||
log.Debug().Str("url_path", path).Msg("filesystem.DeleteCalendarObject()")
|
log.Debug().Str("path", path).Msg("filesystem.DeleteCalendarObject()")
|
||||||
|
|
||||||
localPath, err := b.safeLocalCalDAVPath(ctx, path)
|
localPath, err := b.safeLocalCalDAVPath(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -207,19 +207,12 @@ func (b *filesystemBackend) ListAddressBooks(ctx context.Context) ([]carddav.Add
|
|||||||
if err == nil && len(result) == 0 {
|
if err == nil && len(result) == 0 {
|
||||||
// Nothing here yet? Create the default address book
|
// Nothing here yet? Create the default address book
|
||||||
log.Debug().Msg("no address books found, creating default address book")
|
log.Debug().Msg("no address books found, creating default address book")
|
||||||
ab, err_ := b.createDefaultAddressBook(ctx)
|
ab, err := b.createDefaultAddressBook(ctx)
|
||||||
if err_ != nil {
|
if err == nil {
|
||||||
log.Debug().Int("results", len(result)).Bool("success", false).Str("error", err_.Error()).Msg("filesystem.ListAddressBooks() done")
|
|
||||||
return nil, fmt.Errorf("error creating default address book: %s", err_.Error())
|
|
||||||
}
|
|
||||||
result = append(result, *ab)
|
result = append(result, *ab)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Warn().Int("results", len(result)).Bool("success", false).Str("error", err.Error()).Msg("filesystem.ListAddressBooks() done")
|
|
||||||
} else {
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.ListAddressBooks() done")
|
|
||||||
}
|
}
|
||||||
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.ListAddressBooks() done")
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,15 +225,14 @@ func (b *filesystemBackend) GetAddressBook(ctx context.Context, urlPath string)
|
|||||||
}
|
}
|
||||||
localPath = filepath.Join(localPath, addressBookFileName)
|
localPath = filepath.Join(localPath, addressBookFileName)
|
||||||
|
|
||||||
log.Debug().Str("local_path", localPath).Msg("loading addressbook")
|
log.Debug().Str("path", localPath).Msg("loading addressbook")
|
||||||
|
|
||||||
data, readErr := os.ReadFile(localPath)
|
data, err := os.ReadFile(localPath)
|
||||||
|
if err != nil {
|
||||||
if readErr != nil {
|
if os.IsNotExist(err) {
|
||||||
if os.IsNotExist(readErr) {
|
|
||||||
return nil, webdav.NewHTTPError(404, err)
|
return nil, webdav.NewHTTPError(404, err)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("error opening address book: %s", readErr.Error())
|
return nil, fmt.Errorf("error opening address book: %s", err.Error())
|
||||||
}
|
}
|
||||||
var addressBook carddav.AddressBook
|
var addressBook carddav.AddressBook
|
||||||
err = json.Unmarshal(data, &addressBook)
|
err = json.Unmarshal(data, &addressBook)
|
||||||
@ -252,7 +244,7 @@ func (b *filesystemBackend) GetAddressBook(ctx context.Context, urlPath string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) GetAddressObject(ctx context.Context, objPath string, req *carddav.AddressDataRequest) (*carddav.AddressObject, error) {
|
func (b *filesystemBackend) GetAddressObject(ctx context.Context, objPath string, req *carddav.AddressDataRequest) (*carddav.AddressObject, error) {
|
||||||
log.Debug().Str("url_path", objPath).Msg("filesystem.GetAddressObject()")
|
log.Debug().Str("path", objPath).Msg("filesystem.GetAddressObject()")
|
||||||
|
|
||||||
localPath, err := b.safeLocalCardDAVPath(ctx, objPath)
|
localPath, err := b.safeLocalCardDAVPath(ctx, objPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -274,6 +266,7 @@ func (b *filesystemBackend) GetAddressObject(ctx context.Context, objPath string
|
|||||||
|
|
||||||
card, err := vcardFromFile(localPath, propFilter)
|
card, err := vcardFromFile(localPath, propFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug().Str("path", localPath).Err(err).Msg("error reading calendar")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,11 +294,7 @@ func (b *filesystemBackend) ListAddressObjects(ctx context.Context, urlPath stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
result, err := b.loadAllAddressObjects(ctx, urlPath, propFilter)
|
result, err := b.loadAllAddressObjects(ctx, urlPath, propFilter)
|
||||||
if err != nil {
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.ListAddressObjects() done")
|
||||||
log.Warn().Int("results", len(result)).Bool("success", false).Str("error", err.Error()).Msg("filesystem.ListAddressObjects() done")
|
|
||||||
} else {
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.ListAddressObjects() done")
|
|
||||||
}
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,24 +307,18 @@ func (b *filesystemBackend) QueryAddressObjects(ctx context.Context, urlPath str
|
|||||||
}
|
}
|
||||||
|
|
||||||
result, err := b.loadAllAddressObjects(ctx, urlPath, propFilter)
|
result, err := b.loadAllAddressObjects(ctx, urlPath, propFilter)
|
||||||
|
log.Debug().Int("results", len(result)).Err(err).Msg("filesystem.QueryAddressObjects() load done")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Int("results", len(result)).Str("error", err.Error()).Msg("filesystem.QueryAddressObjects() error loading")
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Int("results", len(result)).Bool("success", true).Msg("filesystem.QueryAddressObjects() load done")
|
|
||||||
|
|
||||||
filtered, err := carddav.Filter(query, result)
|
filtered, err := carddav.Filter(query, result)
|
||||||
if err != nil {
|
log.Debug().Int("results", len(filtered)).Err(err).Msg("filesystem.QueryAddressObjects() filter done")
|
||||||
log.Warn().Int("results", len(result)).Str("error", err.Error()).Msg("filesystem.QueryAddressObjects() error filtering")
|
return filtered, err
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
log.Debug().Int("results", len(filtered)).Bool("success", true).Msg("filesystem.QueryAddressObjects() done")
|
|
||||||
return filtered, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string, card vcard.Card, opts *carddav.PutAddressObjectOptions) (loc string, err error) {
|
func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string, card vcard.Card, opts *carddav.PutAddressObjectOptions) (loc string, err error) {
|
||||||
log.Debug().Str("url_path", objPath).Msg("filesystem.PutAddressObject()")
|
log.Debug().Str("path", objPath).Msg("filesystem.PutAddressObject()")
|
||||||
|
|
||||||
// Object always get saved as <UID>.vcf
|
// Object always get saved as <UID>.vcf
|
||||||
dirname, _ := path.Split(objPath)
|
dirname, _ := path.Split(objPath)
|
||||||
@ -388,7 +371,7 @@ func (b *filesystemBackend) PutAddressObject(ctx context.Context, objPath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *filesystemBackend) DeleteAddressObject(ctx context.Context, path string) error {
|
func (b *filesystemBackend) DeleteAddressObject(ctx context.Context, path string) error {
|
||||||
log.Debug().Str("url_path", path).Msg("filesystem.DeleteAddressObject()")
|
log.Debug().Str("path", path).Msg("filesystem.DeleteAddressObject()")
|
||||||
|
|
||||||
localPath, err := b.safeLocalCardDAVPath(ctx, path)
|
localPath, err := b.safeLocalCardDAVPath(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user