Skip to content

Files Offline PR Review

Ed Mozley edited this page Dec 1, 2026 · 1 revision

Files "Make available offline" - PR review

PR #488 by @cloudcogsio · Issue #285 · Verdict: merge + fix · 5.15.0

When Files is kept in S3-compatible storage, a person can now right-click a file or folder and choose Make available offline. A copy is kept on the FreeITSM server and read first, so the file opens faster and still opens while S3 cannot be reached. S3 stays the master. User page: Files § Make available offline. How it works: Files offline copies - Developer Guide.

This is the next piece of the storage series @cloudcogsio proposed - after S3 storage (#318) and the recycle bin (#353). It is a big, careful piece of work: 3,200 lines, 178 tests, and a write-up in the PR that answered most review questions before they were asked. Thank you.

✅ What was good - keep it this way

What Why it matters
A mark covers only what its maker can open, checked every time The background job never does what that person could not have done by hand. A folder closed to them is not copied, whoever marked the folder above.
The nearest effective mark wins, as permissions inherit One rule people already know. A deactivated person's mark is passed over and the mark above takes over, so a kept folder stays kept when someone leaves.
One write path (FilesOfflineService), one named lock, one transaction, deletes after the commit A mark made at the same moment as a removal never has its fresh copy deleted by it.
Copies checked by size and SHA-256, then renamed into place A half-written or wrong copy is never served.
Big files carried over several runs (.part resumed with a range read) A run never passes its time limit, and an outage keeps what was fetched.
Failures told apart - outage, disk full, out of time, this file's own problem An S3 outage does not mark every file "failed"; a missing file is retried a day later instead of every five minutes.
Ticks from a table the job writes (files_offline_folders) A list load is one indexed lookup, never a walk of the files: 0.001 s for a folder with 300,000 files under it.
"Cannot tell" is never "different" for an old storage folder The same rule the S3 move cleanup follows. An old folder that might be the current one is listed, never emptied by itself.
Invisible until used Installs that keep Files in a server folder see nothing new; before Database Verification, Files works as before and marking says to run it.
Limit and a 1 GB disk floor Offline copies can never fill the disk that uploads need.
Help, strings and tests in the PR The in-app help section was already written in the house style.

🔧 What was fixed when merging - and why

Merged with git merge --no-ff under the contributor's name (75ba2bf79), then one follow-up commit (d18c6c94c).

1. The offline folder could be created without its deny rules 🟠

Was: copyKey() and the upload copy created <storage root>/offline/... with a plain mkdir.

Could have: on an S3 install with a custom storage folder, that folder may never have been created - nothing local was ever stored in it, so filesStorageRoot() (which guards it with uploadPrepareDir()) never ran. The first offline copy then made the folder with no .htaccess or web.config. The default uploads/files/ was safe, because its rules are in the repo; a custom folder inside the web root was not.

Now: both paths call filesStorageRoot($conn) first, which creates the root and drops the deny rules, exactly as a local store does. filesOfflineRoot() still creates nothing, because every S3 download calls it.

Lesson: a folder that holds stored files is created through the one function that guards it, even when it is "only a cache".

2. A resumed copy kept its first write's time

copyKey() now touches the finished copy after the rename, as commitUploadCopy() already did, so a copy carried over several runs is dated when it was completed.

3. Four tests failed on Windows

tests/files-offline.php built its expected paths from sys_get_temp_dir(), which has backslashes on Windows, while the code stores storage folders with forward slashes. Four checks failed and one threw. A zzTempDir() helper normalises them; nothing in the code changed. Now 177 / 177.

❓ The author's questions

  1. Modify to mark, or View with the limit as the guard? - Modify, as built. A mark makes the server hold a copy, which costs disk and changes what happens to everyone's reads of that folder: that is changing the folder, not reading it. The limit protects the disk, not the decision. Anyone who needs it on a folder they can only view can ask someone with Modify.
  2. Should a deactivated person's marks stop counting? - Yes, as built. A mark with nobody behind it should not keep copying, and its maker's permissions can no longer be checked in any meaningful way. The Storage tab already says how many such marks there are, and anyone with Modify can make one again as their own.

🧪 What was checked

Question How Result
His tests, unchanged code prtest (Windows) 152 pass, 4 fail - all on path separators in the test
His tests after the fixes prtest 177 passed, 0 failed
Analyst references tests/analyst-lifecycle.php 21 passed
Schema and indexes Database Verification on prtest; gen_db_verify_indexes.php Tables created; generated index file unchanged
The CI guards colour, font size, duplicate ids, web exposure, htaccess, template div balance, GET must not write and the rest All pass

Left as it is

  • No foreign key from files_offline_folders to files_folders: the job rewrites that table on every run, so a row for a deleted folder lives five minutes at most.

Still to do for the whole storage series: Storage series - follow-ups and gaps.

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally