MCPcopy
hub / github.com/gtsteffaniak/filebrowser / OpenFile

Method OpenFile

backend/http/webdav.go:265–301  ·  view source on GitHub ↗
(ctx context.Context, requestPath string, flag int, perm os.FileMode)

Source from the content-addressed store, hash-verified

263}
264
265func (ffs *filteredFileSystem) OpenFile(ctx context.Context, requestPath string, flag int, perm os.FileMode) (webdav.File, error) {
266 // Check if this is a write operation
267 isWrite := (flag&os.O_WRONLY) != 0 || (flag&os.O_RDWR) != 0 || (flag&os.O_CREATE) != 0
268
269 if isWrite {
270 // Check user permissions first
271 if !ffs.user.Permissions.Create && !ffs.user.Permissions.Modify {
272 return nil, fmt.Errorf("write permission required")
273 }
274
275 // For write operations, check access
276 if err := ffs.checkAccess(requestPath); err != nil {
277 logger.Debugf("OpenFile: write access denied for %s: %v", requestPath, err)
278 return nil, err
279 }
280 }
281
282 file, err := ffs.fs.OpenFile(ctx, requestPath, flag, perm)
283 if err != nil {
284 return nil, err
285 }
286
287 stat, err := file.Stat()
288 if err != nil {
289 file.Close()
290 return nil, err
291 }
292
293 // Wrap the file to filter directory listings
294 // name is the request path (without user scope)
295 return &filteredFile{
296 File: file,
297 fs: ffs,
298 requestPath: requestPath,
299 isDir: stat.IsDir(),
300 }, nil
301}
302
303func (ffs *filteredFileSystem) RemoveAll(ctx context.Context, requestPath string) error {
304 if !ffs.user.Permissions.Delete {

Callers 5

archiveCreateHandlerFunction · 0.80
resourcePostHandlerFunction · 0.80
WriteFileFunction · 0.80
copySingleFileFunction · 0.80

Calls 4

checkAccessMethod · 0.95
StatMethod · 0.80
CloseMethod · 0.80
IsDirMethod · 0.45

Tested by

no test coverage detected