Skip to content

Commit

Permalink
server: rTorrent: ensure the temporary file is world-readable
Browse files Browse the repository at this point in the history
This allows rTorrent to read the file when the Flood and rTorrent
are running in different users and when the system has a restrictive
default umask.

Bug: #86
  • Loading branch information
jesec committed Nov 13, 2020
1 parent 006512c commit ac11f31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/services/rTorrent/clientGatewayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
}: Required<AddTorrentByFileOptions>): Promise<void> {
const torrentPaths = await Promise.all(
files.map(async (file) => {
return saveBufferToTempFile(Buffer.from(file, 'base64'), 'torrent');
return saveBufferToTempFile(Buffer.from(file, 'base64'), 'torrent', {mode: 0o664});
}),
);

Expand Down
10 changes: 7 additions & 3 deletions server/util/tempFileUtil.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, {AxiosError, AxiosResponse} from 'axios';
import crypto from 'crypto';
import fs from 'fs';
import fs, {WriteFileOptions} from 'fs';

import {getTempPath} from '../models/TemporaryStorage';

Expand Down Expand Up @@ -33,10 +33,14 @@ const delayedDelete = (tempPath: string): void => {
* @param {string} extension - file extension of temp file
* @return {string} - path of saved temporary file. deleted after 5 minutes.
*/
export const saveBufferToTempFile = async (buffer: Buffer, extension?: string): Promise<string> => {
export const saveBufferToTempFile = async (
buffer: Buffer,
extension?: string,
options?: WriteFileOptions,
): Promise<string> => {
const tempPath = getTempFilePath(extension);

fs.writeFileSync(tempPath, buffer);
fs.writeFileSync(tempPath, buffer, options);

delayedDelete(tempPath);

Expand Down

0 comments on commit ac11f31

Please sign in to comment.