mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-04-05 15:36:15 +00:00
fix(provider): enhance file opening logic with alternate path. Handling broken cases to be compatible with Bitech clients
* Implemented alternate path handling for file retrieval * Improved error messaging for file not found scenarios
This commit is contained in:
@@ -98,6 +98,7 @@ func (p *EmbedFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
// Apply prefix stripping by prepending the prefix to the requested path
|
// Apply prefix stripping by prepending the prefix to the requested path
|
||||||
actualPath := name
|
actualPath := name
|
||||||
|
alternatePath := ""
|
||||||
if p.stripPrefix != "" {
|
if p.stripPrefix != "" {
|
||||||
// Clean the paths to handle leading/trailing slashes
|
// Clean the paths to handle leading/trailing slashes
|
||||||
prefix := strings.Trim(p.stripPrefix, "/")
|
prefix := strings.Trim(p.stripPrefix, "/")
|
||||||
@@ -105,12 +106,25 @@ func (p *EmbedFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
actualPath = path.Join(prefix, cleanName)
|
actualPath = path.Join(prefix, cleanName)
|
||||||
|
alternatePath = cleanName
|
||||||
} else {
|
} else {
|
||||||
actualPath = cleanName
|
actualPath = cleanName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// First try the actual path with prefix
|
||||||
|
if file, err := p.fs.Open(actualPath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
return p.fs.Open(actualPath)
|
// If alternate path is different, try it as well
|
||||||
|
if alternatePath != "" && alternatePath != actualPath {
|
||||||
|
if file, err := p.fs.Open(alternatePath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If both attempts fail, return the error from the first attempt
|
||||||
|
return nil, fmt.Errorf("file not found: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close releases any resources held by the provider.
|
// Close releases any resources held by the provider.
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ func (p *LocalFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
// Apply prefix stripping by prepending the prefix to the requested path
|
// Apply prefix stripping by prepending the prefix to the requested path
|
||||||
actualPath := name
|
actualPath := name
|
||||||
|
alternatePath := ""
|
||||||
if p.stripPrefix != "" {
|
if p.stripPrefix != "" {
|
||||||
// Clean the paths to handle leading/trailing slashes
|
// Clean the paths to handle leading/trailing slashes
|
||||||
prefix := strings.Trim(p.stripPrefix, "/")
|
prefix := strings.Trim(p.stripPrefix, "/")
|
||||||
@@ -60,12 +61,26 @@ func (p *LocalFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
actualPath = path.Join(prefix, cleanName)
|
actualPath = path.Join(prefix, cleanName)
|
||||||
|
alternatePath = cleanName
|
||||||
} else {
|
} else {
|
||||||
actualPath = cleanName
|
actualPath = cleanName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.fs.Open(actualPath)
|
// First try the actual path with prefix
|
||||||
|
if file, err := p.fs.Open(actualPath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If alternate path is different, try it as well
|
||||||
|
if alternatePath != "" && alternatePath != actualPath {
|
||||||
|
if file, err := p.fs.Open(alternatePath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If both attempts fail, return the error from the first attempt
|
||||||
|
return nil, fmt.Errorf("file not found: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close releases any resources held by the provider.
|
// Close releases any resources held by the provider.
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ func (p *ZipFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
// Apply prefix stripping by prepending the prefix to the requested path
|
// Apply prefix stripping by prepending the prefix to the requested path
|
||||||
actualPath := name
|
actualPath := name
|
||||||
|
alternatePath := ""
|
||||||
if p.stripPrefix != "" {
|
if p.stripPrefix != "" {
|
||||||
// Clean the paths to handle leading/trailing slashes
|
// Clean the paths to handle leading/trailing slashes
|
||||||
prefix := strings.Trim(p.stripPrefix, "/")
|
prefix := strings.Trim(p.stripPrefix, "/")
|
||||||
@@ -63,12 +64,26 @@ func (p *ZipFSProvider) Open(name string) (fs.File, error) {
|
|||||||
|
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
actualPath = path.Join(prefix, cleanName)
|
actualPath = path.Join(prefix, cleanName)
|
||||||
|
alternatePath = cleanName
|
||||||
} else {
|
} else {
|
||||||
actualPath = cleanName
|
actualPath = cleanName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.zipFS.Open(actualPath)
|
// First try the actual path with prefix
|
||||||
|
if file, err := p.zipFS.Open(actualPath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If alternate path is different, try it as well
|
||||||
|
if alternatePath != "" && alternatePath != actualPath {
|
||||||
|
if file, err := p.zipFS.Open(alternatePath); err == nil {
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If both attempts fail, return the error from the first attempt
|
||||||
|
return nil, fmt.Errorf("file not found: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close releases resources held by the zip reader.
|
// Close releases resources held by the zip reader.
|
||||||
|
|||||||
Reference in New Issue
Block a user