mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 05:27:04 +08:00 
			
		
		
		
	chore (plg_backend_local): improve error message
This commit is contained in:
		@ -76,7 +76,7 @@ func SafeOsMkdir(path string, mode os.FileMode) error {
 | 
				
			|||||||
		Log.Debug("common::files safeOsMkdir err[%s] path[%s]", err.Error(), path)
 | 
							Log.Debug("common::files safeOsMkdir err[%s] path[%s]", err.Error(), path)
 | 
				
			||||||
		return ErrFilesystemError
 | 
							return ErrFilesystemError
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return os.Mkdir(path, mode)
 | 
						return processError(os.Mkdir(path, mode))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SafeOsRemove(path string) error {
 | 
					func SafeOsRemove(path string) error {
 | 
				
			||||||
@ -84,7 +84,7 @@ func SafeOsRemove(path string) error {
 | 
				
			|||||||
		Log.Debug("common::files safeOsRemove err[%s] path[%s]", err.Error(), path)
 | 
							Log.Debug("common::files safeOsRemove err[%s] path[%s]", err.Error(), path)
 | 
				
			||||||
		return ErrFilesystemError
 | 
							return ErrFilesystemError
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return os.Remove(path)
 | 
						return processError(os.Remove(path))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SafeOsRemoveAll(path string) error {
 | 
					func SafeOsRemoveAll(path string) error {
 | 
				
			||||||
@ -92,7 +92,7 @@ func SafeOsRemoveAll(path string) error {
 | 
				
			|||||||
		Log.Debug("common::files safeOsRemoveAll err[%s] path[%s]", err.Error(), path)
 | 
							Log.Debug("common::files safeOsRemoveAll err[%s] path[%s]", err.Error(), path)
 | 
				
			||||||
		return ErrFilesystemError
 | 
							return ErrFilesystemError
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return os.RemoveAll(path)
 | 
						return processError(os.RemoveAll(path))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SafeOsRename(from string, to string) error {
 | 
					func SafeOsRename(from string, to string) error {
 | 
				
			||||||
@ -103,7 +103,7 @@ func SafeOsRename(from string, to string) error {
 | 
				
			|||||||
		Log.Debug("common::files safeOsRemove err[%s] to[%s]", err.Error(), to)
 | 
							Log.Debug("common::files safeOsRemove err[%s] to[%s]", err.Error(), to)
 | 
				
			||||||
		return ErrFilesystemError
 | 
							return ErrFilesystemError
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return os.Rename(from, to)
 | 
						return processError(os.Rename(from, to))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func safePath(path string) error {
 | 
					func safePath(path string) error {
 | 
				
			||||||
@ -121,3 +121,16 @@ func safePath(path string) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func processError(err error) error {
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if pe, ok := err.(*os.PathError); ok {
 | 
				
			||||||
 | 
							return pe.Err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if le, ok := err.(*os.LinkError); ok {
 | 
				
			||||||
 | 
							return le.Err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -13,8 +13,11 @@ func SafeOsOpenFile(path string, flag int, perm os.FileMode) (*os.File, error) {
 | 
				
			|||||||
		return nil, ErrFilesystemError
 | 
							return nil, ErrFilesystemError
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	f, err := os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm)
 | 
						f, err := os.OpenFile(path, flag|syscall.O_NOFOLLOW, perm)
 | 
				
			||||||
	if err != nil && errors.Is(err, fs.ErrNotExist) {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if errors.Is(err, fs.ErrNotExist) {
 | 
				
			||||||
			return nil, ErrNotFound
 | 
								return nil, ErrNotFound
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							return nil, processError(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return f, err
 | 
						return f, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user