38 lines
775 B
Go
38 lines
775 B
Go
package post
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
)
|
|
|
|
type UnifiedPost interface {
|
|
ID() string
|
|
Name() string
|
|
Author() string
|
|
Comment() string
|
|
Tags() []string
|
|
Files() []string
|
|
URL() string
|
|
Stringer() string
|
|
Type() string
|
|
}
|
|
|
|
// WriteAttributes writes info from post to file's metadata
|
|
func WriteAttributes(filename string, post UnifiedPost) (err error) {
|
|
var tags string
|
|
for _, tag := range post.Tags() {
|
|
tags = fmt.Sprintf("%s,%s", tags, tag)
|
|
}
|
|
err = syscall.Setxattr(filename, "user.xdg.tags", []byte(tags), 0)
|
|
if err != nil {
|
|
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
|
return
|
|
}
|
|
err = syscall.Setxattr(filename, "user.xdg.comment", []byte(post.Comment()), 0)
|
|
if err != nil {
|
|
err = fmt.Errorf("WriteAttributes: %s", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|