Repository navigation
fix(uploads): stage outgoing documents in the OS temp directory - #287
Open
Realmagnum wants to merge 1 commit into
Open
Realmagnum wants to merge 1 commit into
Realmagnum wants to merge 1 commit into
Conversation
sendDocument() wrote the upload scratch file to dist/.tmp inside the installed package. A global npm install is owned by root, so a bot running as an unprivileged user failed with EACCES on mkdir and every tool-output file upload was dropped. Use os.tmpdir() instead, which is writable for the process and honours TMPDIR.
Owner
|
@Realmagnum thanks for the fix! You found the root cause correctly: Required: We don't need a temp file at all, because grammY accepts a buffer directly: await destination.api.sendDocument(
destination.chatId,
new InputFile(fileData.buffer, fileData.filename),
{ caption: fileData.caption, ...options },
);
This lets us remove TEMP_DIR, mkdir/writeFile/unlink and the unused imports. It also fixes collisions when two files with the same name are sent at the same time. Please update the test to check that sendDocument gets an InputFile with the right filename.
Optional: the .tmp/ entry in .gitignore can be removed after this change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
TelegramEventDelivery.sendDocument()now stages the outgoing document underos.tmpdir()/opencode-telegram-botinstead of<installed package>/dist/.tmp.Why
The scratch directory was resolved relative to the compiled module:
For a global install (
npm i -g) the package directory is owned by root and is not writable by the user the bot runs as, sofs.mkdir(TEMP_DIR)failed withEACCESand every tool-output file was dropped:os.tmpdir()is writable for the process and honoursTMPDIR, so uploads no longer depend on installation layout or ownership (global install, Docker, read-only package dir).Fixes #286.
Changes
src/bot/events/telegram-event-delivery.ts— useos.tmpdir(); drop the now-unusedfileURLToPath/__dirnamescaffolding.tests/bot/events/telegram-event-delivery.test.ts— new test asserting the staged path lives under the OS temp directory, not beside the package.Testing
npx vitest run tests/bot/events/telegram-event-delivery.test.ts— 6 passednpm test— 202 files, 2807 passed, 7 skippednpm run lint,npm run typecheck— cleandist/: theInputFilehanded tosendDocumentpointed at/tmp/opencode-telegram-bot/write_x.txt, the file existed with the expected content while sending, and was removed afterwards.