lib/config, lib/ignore: Write Windows line endings (fixes #7115) (#8052)

This commit is contained in:
Jakob Borg
2021-11-22 09:38:24 +01:00
committed by GitHub
parent 4b750b6dc3
commit 1754c93370
6 changed files with 92 additions and 3 deletions
+35
View File
@@ -594,6 +594,41 @@ func TestNewSaveLoad(t *testing.T) {
}
}
func TestWindowsLineEndings(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Windows specific")
}
dir, err := os.MkdirTemp("", "syncthing-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
path := filepath.Join(dir, "config.xml")
os.Remove(path)
defer os.Remove(path)
intCfg := New(device1)
cfg := wrap(path, intCfg, device1)
defer cfg.stop()
if err := cfg.Save(); err != nil {
t.Error(err)
}
bs, err := os.ReadFile(path)
if err != nil {
t.Error(err)
}
unixLineEndings := bytes.Count(bs, []byte("\n"))
windowsLineEndings := bytes.Count(bs, []byte("\r\n"))
if unixLineEndings == 0 || windowsLineEndings != unixLineEndings {
t.Error("expected there to be a non-zero number of Windows line endings")
}
}
func TestPrepare(t *testing.T) {
var cfg Configuration
+1 -1
View File
@@ -502,7 +502,7 @@ func (w *wrapper) Save() error {
return err
}
if err := w.cfg.WriteXML(fd); err != nil {
if err := w.cfg.WriteXML(osutil.LineEndingsWriter(fd)); err != nil {
l.Debugln("WriteXML:", err)
fd.Close()
return err