mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 05:27:04 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			499 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			499 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package common
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
	"io/fs"
 | 
						|
	"os"
 | 
						|
	"syscall"
 | 
						|
)
 | 
						|
 | 
						|
func SafeOsOpenFile(path string, flag int, perm os.FileMode) (*os.File, error) {
 | 
						|
	if err := safePath(path); err != nil {
 | 
						|
		Log.Debug("common::files safeOsOpenFile err[%s] path[%s]", err.Error(), path)
 | 
						|
		return nil, ErrFilesystemError
 | 
						|
	}
 | 
						|
	f, err := os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm)
 | 
						|
	if err != nil {
 | 
						|
		if errors.Is(err, fs.ErrNotExist) {
 | 
						|
			return nil, ErrNotFound
 | 
						|
		}
 | 
						|
		return nil, processError(err)
 | 
						|
	}
 | 
						|
	return f, err
 | 
						|
}
 |