Skip to content

Bad folder size in app #456

@p0358

Description

@p0358

Describe the bug
The folder size uses /api/folder-size API endpoint, which defaults to ., being current directory:

path = request.args.get('path', default='.', type=str)

But in Dockerfile, WORKDIR is set to /, so it ends up being the container's root, which not only ends up giving us completely bogus size in return, but it also often ends up in an error, since it tries to stat paths like ./proc/330/task/332/fdinfo/17 and ends up with errors like:

ERROR   app.log_exception:1455 | Exception on /api/folder-size [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.10/dist-packages/flask_login/utils.py", line 303, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/fireshare/api.py", line 294, in folder_size
size_bytes = get_folder_size(path)
File "/usr/local/lib/python3.10/dist-packages/fireshare/api.py", line 286, in get_folder_size
total_size += os.path.getsize(fp)
File "/usr/lib/python3.10/genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: './proc/330/task/332/fdinfo/17'
[2026-02-19 11:55:56,431] ERROR in app: Exception on /api/folder-size [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.10/dist-packages/flask_login/utils.py", line 303, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/fireshare/api.py", line 294, in folder_size
size_bytes = get_folder_size(path)
File "/usr/local/lib/python3.10/dist-packages/fireshare/api.py", line 286, in get_folder_size
total_size += os.path.getsize(fp)
File "/usr/lib/python3.10/genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: './proc/330/task/332/fdinfo/17'

(in this case, the direct cause is probably a race condition between listing filesystem tree and then stat-ing the files, but that's another reason not to scan / which includes dynamic folders like /proc, /dev and /sys...)

Furthermore, even after passing the video path as the parameter for a test, I noticed it returned 100 MB, which was completely wrong, even though the raw size seemed correct (the videos actually take ~55 MB). Turns out there's this rounding:

rounded_mb = round(size_mb / 100) * 100

I think that rounding should be removed and just round it to 1 MB, since rounding to a whole 100 MB is very confusing and it doesn't make it look better in any way either. Instead, it just looks like it's counting something wrongly and makes you go investigate what's up with that number.

Then rounding higher units down to a single digit after the decimal separator should be fine on the other hand, when the library is large enough for that.

To Reproduce

  1. Open Fireshare web UI
  2. Notice that the size is either wrong or doesn't work at all

Expected behavior

  1. It should only check the size of configured video path (since we care about the size of videos, not of whatever junk is in the container's filesystem), that should be the default path to check
  2. It should round MB to 1 MB granularity

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Browser [e.g. chrome, safari, firefox]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions