Explorar el Código

fix: create output directory before HandBrake processing

Ensures the output directory exists before spawning HandBrakeCLI process.
Fixes 'avio_open2 failed, errno -2' error when output directory is missing.

This commonly occurs when:
- Output path is on network share that may not have directory structure
- Dataset output directories haven't been created yet
- Running on different machines with different filesystem layouts
Timothy Pomeroy hace 1 mes
padre
commit
83c6c62556
Se han modificado 1 ficheros con 16 adiciones y 0 borrados
  1. 16 0
      apps/service/src/handbrake.service.ts

+ 16 - 0
apps/service/src/handbrake.service.ts

@@ -1,5 +1,6 @@
 import { Injectable, Logger } from '@nestjs/common';
 import { spawn } from 'child_process';
+import { mkdirSync } from 'fs';
 import path from 'path';
 import { DbService } from './db.service';
 import { EventsGateway } from './events.gateway';
@@ -21,6 +22,21 @@ export class HandbrakeService {
   ): Promise<boolean> {
     return new Promise((resolve, reject) => {
       try {
+        // Ensure output directory exists
+        const outputDir = path.dirname(output);
+        try {
+          mkdirSync(outputDir, { recursive: true });
+          this.logger.log(`Ensured output directory exists: ${outputDir}`);
+        } catch (err) {
+          this.logger.error(
+            `Failed to create output directory: ${outputDir}`,
+            err,
+          );
+          return reject(
+            new Error(`Cannot create output directory: ${outputDir}`),
+          );
+        }
+
         const inputName = path.basename(input);
         const outputName = path.basename(output);
         let progressStarted = false;