olcli icon indicating copy to clipboard operation
olcli copied to clipboard

upload: absolute paths mirror local directory structure into the project; add --to option

Open aloth opened this issue 3 months ago • 0 comments

Problem

olcli upload uses the local file path as the remote path. The upload action only strips leading ./ and leading slashes:

const fileName = file.replace(/^(\.\/)+/, '').replace(/^\/+/, '');

The resulting string is used as the destination path inside the Overleaf project.

This is correct for relative paths:

olcli upload figures/diagram.png   ->  figures/diagram.png

But it breaks for absolute paths:

olcli upload /tmp/tmp.abc123/paper.tex   ->  tmp/tmp.abc123/paper.tex

The leading slash is removed, the rest of the local directory structure is preserved, and Overleaf happily creates the intermediate folders. The file ends up in a mirrored tmp/tmp.abc123/ tree instead of the project root, so a later olcli download paper.tex fails with a confusing "not found".

Relative paths containing .. have the same class of problem and can produce unexpected remote layouts.

How it surfaced

Noticed by @SomeBottle while working on #38: test/e2e.sh uploads using $TEST_FILE (an absolute path under $TEST_DIR) but downloads using ${TEST_ID}.txt (project root), so the download test failed. The workaround in #38 is to cd "$TEST_DIR" first and upload with a relative path. That makes the suite pass but hides the underlying bug.

Proposed fix

  1. Absolute paths should collapse to the basename by default. /tmp/xxx/paper.tex -> paper.tex. Mirroring the local filesystem hierarchy from / into an Overleaf project is never the intent.
  2. Relative paths keep current behavior, so figures/diagram.png -> figures/diagram.png still works.
  3. Normalize .. segments instead of passing them through, and reject or collapse anything that would escape the project root.
  4. Add an explicit --to <remote-path> option so the destination can always be stated directly:
olcli upload /tmp/xxx/file.txt --to sub/file.txt

--to takes precedence over the derived path. It composes with the existing --folder option in the obvious way (a --to path is relative to the folder, or --to wins if both specify a location - to be decided during implementation).

  1. Once fixed, revert the cd "$TEST_DIR" workarounds in test/e2e.sh so the suite exercises absolute paths again.

Compatibility

Item 1 is technically a behavior change, but the current behavior for absolute paths is not something anyone can be relying on deliberately. Worth calling out in the changelog.

aloth avatar Aug 08 '26 08:08 aloth