Storage: добавлено, что строки с суффиксом "==" - регистрозависимые

Этот коммит содержится в:
Softonik 2024-03-02 04:13:56 +03:00 коммит произвёл Nobody
родитель 79cc4608fa
коммит 62af6c08d2

Просмотреть файл

@ -16,7 +16,7 @@ type Storage struct {
filename string filename string
fd *os.File fd *os.File
watcher *fsnotify.Watcher watcher *fsnotify.Watcher
list List list, listCase List
lock sync.RWMutex lock sync.RWMutex
} }
type List []string type List []string
@ -40,7 +40,7 @@ func (s *Storage) reReadFile() error {
return err return err
} }
var newlist List var newlist, newlistCase List
scanner := bufio.NewScanner(fd) scanner := bufio.NewScanner(fd)
for { for {
@ -50,13 +50,19 @@ func (s *Storage) reReadFile() error {
} }
line := scanner.Text() line := scanner.Text()
if strings.HasSuffix(line, "==") {
newlistCase = append(newlistCase, line[:len(line)-2])
} else {
newlist = append(newlist, line) newlist = append(newlist, line)
} }
}
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.list = newlist s.list = newlist
s.listCase = newlistCase
return nil return nil
} }
@ -148,6 +154,12 @@ func (s *Storage) GetList() *List {
return &s.list return &s.list
} }
func (s *Storage) GetListCase() *List {
s.lock.RLock()
defer s.lock.RUnlock()
return &s.listCase
}
func (s *Storage) AddLine(p, v string) error { func (s *Storage) AddLine(p, v string) error {
return nil return nil
@ -158,6 +170,7 @@ func (s *Storage) Save() error {
} }
func (s *Storage) doSave() error { func (s *Storage) doSave() error {
buf := strings.Join(s.list, "\n") buf := strings.Join(s.list, "\n")
buf += strings.Join(s.listCase, "==\n")
return lib.WriteFile(s.filename, buf) return lib.WriteFile(s.filename, buf)
} }
func (s *Storage) makeBackup() { func (s *Storage) makeBackup() {