Fix truncation when saving file changes; closes pterodactyl/panel#1956

This commit is contained in:
Dane Everitt 2020-04-25 13:12:17 -07:00
parent 7321fe1421
commit 46056dbce9
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -204,6 +204,11 @@ func (f *ConfigurationFile) parseXmlFile(path string) error {
// Ensure the XML is indented properly. // Ensure the XML is indented properly.
doc.Indent(2) doc.Indent(2)
// Truncate the file before attempting to write the changes.
if err := os.Truncate(path, 0); err != nil {
return err
}
// Write the XML to the file. // Write the XML to the file.
_, err = doc.WriteTo(file) _, err = doc.WriteTo(file)
@ -261,6 +266,11 @@ func (f *ConfigurationFile) parseIniFile(path string) error {
} }
} }
// Truncate the file before attempting to write the changes.
if err := os.Truncate(path, 0); err != nil {
return err
}
if _, err := cfg.WriteTo(file); err != nil { if _, err := cfg.WriteTo(file); err != nil {
return err return err
} }
@ -387,7 +397,7 @@ func (f *ConfigurationFile) parsePropertiesFile(path string) error {
} }
} }
w, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) w, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil { if err != nil {
return err return err
} }