Skip to content

Commit e2e13ba

Browse files
authored
Merge pull request #458 from DialmasterOrg/fix/ytdlp-update-nonroot-permissions
fix: yt-dlp update failure when run as non-root user (#451)
2 parents 93bcbfa + 45021fa commit e2e13ba

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3535
ca-certificates \
3636
&& rm -rf /var/lib/apt/lists/*
3737

38-
# Download the latest yt-dlp release directly from GitHub
39-
RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \
40-
chmod +x /usr/local/bin/yt-dlp
38+
# Download the latest yt-dlp release to a dedicated writable directory
39+
# so non-root users (YOUTARR_UID/YOUTARR_GID) can self-update at runtime
40+
RUN mkdir -p /opt/yt-dlp && \
41+
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /opt/yt-dlp/yt-dlp && \
42+
chmod 0777 /opt/yt-dlp /opt/yt-dlp/yt-dlp
43+
ENV PATH="/opt/yt-dlp:${PATH}"
4144

4245
# Install Deno
4346
ENV DENO_INSTALL="/usr/local"

server/modules/__tests__/ytdlpModule.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,20 @@ describe('ytdlpModule', () => {
307307
expect(result.message).toContain('Permission denied');
308308
});
309309

310+
it('handles "Unable to write to" permission error', async () => {
311+
const mockProcess = createMockProcess();
312+
spawn.mockReturnValue(mockProcess);
313+
314+
const updatePromise = ytdlpModule.performUpdate();
315+
316+
mockProcess.stderr.emit('data', 'Unable to write to /usr/local/bin/yt-dlp; try running as administrator');
317+
mockProcess.emit('close', 100);
318+
319+
const result = await updatePromise;
320+
expect(result.success).toBe(false);
321+
expect(result.message).toContain('Permission denied');
322+
});
323+
310324
it('handles non-zero exit code', async () => {
311325
const mockProcess = createMockProcess();
312326
spawn.mockReturnValue(mockProcess);

server/modules/ytdlpModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function performUpdate() {
196196
const output = stdout + stderr;
197197

198198
if (code !== 0) {
199-
if (output.includes('Permission denied')) {
199+
if (output.includes('Permission denied') || output.includes('Unable to write to')) {
200200
logger.warn({ output }, 'yt-dlp update failed: permission denied');
201201
resolve({
202202
success: false,

0 commit comments

Comments
 (0)