mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Fix: file close even if file was not opened (#1417)
Fixed a bug where in many implementations of load-file functions the file-close was still executed even if the file-open resulted in an error.
This commit is contained in:
@@ -29,10 +29,10 @@ type Gallery struct {
|
||||
func LoadGalleryFile(filePath string) (*Gallery, error) {
|
||||
var gallery Gallery
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&gallery)
|
||||
|
||||
@@ -33,10 +33,10 @@ type Image struct {
|
||||
func LoadImageFile(filePath string) (*Image, error) {
|
||||
var image Image
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&image)
|
||||
|
||||
@@ -26,10 +26,10 @@ type Mappings struct {
|
||||
func LoadMappingsFile(filePath string) (*Mappings, error) {
|
||||
var mappings Mappings
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&mappings)
|
||||
|
||||
@@ -27,10 +27,10 @@ type Movie struct {
|
||||
func LoadMovieFile(filePath string) (*Movie, error) {
|
||||
var movie Movie
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&movie)
|
||||
|
||||
@@ -40,10 +40,10 @@ type Performer struct {
|
||||
func LoadPerformerFile(filePath string) (*Performer, error) {
|
||||
var performer Performer
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&performer)
|
||||
|
||||
@@ -61,10 +61,10 @@ type Scene struct {
|
||||
func LoadSceneFile(filePath string) (*Scene, error) {
|
||||
var scene Scene
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&scene)
|
||||
|
||||
@@ -27,10 +27,10 @@ type ScrapedItem struct {
|
||||
func LoadScrapedFile(filePath string) ([]ScrapedItem, error) {
|
||||
var scraped []ScrapedItem
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&scraped)
|
||||
|
||||
@@ -22,10 +22,10 @@ type Studio struct {
|
||||
func LoadStudioFile(filePath string) (*Studio, error) {
|
||||
var studio Studio
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&studio)
|
||||
|
||||
@@ -18,10 +18,10 @@ type Tag struct {
|
||||
func LoadTagFile(filePath string) (*Tag, error) {
|
||||
var tag Tag
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&tag)
|
||||
|
||||
@@ -211,10 +211,10 @@ func loadPluginFromYAML(reader io.Reader) (*Config, error) {
|
||||
|
||||
func loadPluginFromYAMLFile(path string) (*Config, error) {
|
||||
file, err := os.Open(path)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
ret, err := loadPluginFromYAML(file)
|
||||
if err != nil {
|
||||
|
||||
@@ -209,10 +209,10 @@ func loadScraperFromYAML(id string, reader io.Reader) (*config, error) {
|
||||
|
||||
func loadScraperFromYAMLFile(path string) (*config, error) {
|
||||
file, err := os.Open(path)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// set id to the filename
|
||||
id := filepath.Base(path)
|
||||
|
||||
Reference in New Issue
Block a user