Lets not read an entire file into memory
This commit is contained in:
parent
5c78cb9ab3
commit
e05c601325
|
@ -31,7 +31,10 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
|
||||||
|
|
||||||
// Get all of the ignored files for a server based on its .pteroignore file in the root.
|
// Get all of the ignored files for a server based on its .pteroignore file in the root.
|
||||||
func (s *Server) getServerwideIgnoredFiles() (string, error) {
|
func (s *Server) getServerwideIgnoredFiles() (string, error) {
|
||||||
f, err := os.Open(path.Join(s.Filesystem().Path(), ".pteroignore"))
|
p := path.Join(s.Filesystem().Path(), ".pteroignore")
|
||||||
|
|
||||||
|
// Stat the file and don't resolve any symlink targets.
|
||||||
|
stat, err := os.Lstat(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -40,6 +43,26 @@ func (s *Server) getServerwideIgnoredFiles() (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not read symlinks.
|
||||||
|
if stat.Mode()&os.ModeSymlink != 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the file is bigger than 32 KiB, don't read it at all.
|
||||||
|
if stat.Size() > 32*1024 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(p)
|
||||||
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the entire file into memory.
|
||||||
b, err := ioutil.ReadAll(f)
|
b, err := ioutil.ReadAll(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -75,7 +98,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||||
}).Info("notified panel of failed backup state")
|
}).Info("notified panel of failed backup state")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Events().PublishJson(BackupCompletedEvent+":"+b.Identifier(), map[string]interface{}{
|
_ = s.Events().PublishJson(BackupCompletedEvent+":"+b.Identifier(), map[string]interface{}{
|
||||||
"uuid": b.Identifier(),
|
"uuid": b.Identifier(),
|
||||||
"is_successful": false,
|
"is_successful": false,
|
||||||
"checksum": "",
|
"checksum": "",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user