{"record":{"id":"c691107380990182","repo":"tonhowtf/omniget","slug":"download-terminou-mas-nao-achei-o-arquivo","errorCode":null,"errorMessage":"download terminou mas nao achei o arquivo","messagePattern":"download terminou mas nao achei o arquivo","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/aria2.rs","lineNumber":139,"sourceCode":"            }\n        }\n        last\n    });\n    let st = child.wait().await?;\n    let last = task.await.unwrap_or_default();\n    if !st.success() {\n        return Err(anyhow!(\"aria2c falhou: {}\", last));\n    }\n    // aria2 decide o nome pelo Content-Disposition/URL; pega o arquivo mais novo da pasta\n    let path = if !opts.file_name.trim().is_empty() {\n        PathBuf::from(&opts.dest_dir).join(opts.file_name.trim())\n    } else {\n        std::fs::read_dir(&opts.dest_dir)?\n            .flatten()\n            .filter(|e| e.path().is_file() && !e.path().to_string_lossy().ends_with(\".aria2\"))\n            .max_by_key(|e| e.metadata().and_then(|m| m.modified()).ok())\n            .map(|e| e.path())\n            .ok_or_else(|| anyhow!(\"download terminou mas nao achei o arquivo\"))?\n    };\n    let bytes = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0);\n    super::report(&progress, &id, \"done\", 100, Some(100), None);\n    Ok(Aria2Result {\n        path: path.to_string_lossy().to_string(),\n        bytes,\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    #[test]\n    fn parses_line() {\n        let (p, s) =\n            super::parse_progress(\"[#2089b0 12MiB/100MiB(12%) CN:16 DL:5.0MiB ETA:10s]\").unwrap();\n        assert_eq!(p, 12);\n        assert_eq!(s, \"5.0MiB\");\n    }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/aria2.rs#L121-L157","documentation":"When opts.file_name is empty, download() infers the output file by listing dest_dir and picking the newest non-`.aria2` regular file by modification time. If the directory has no such file after aria2c exits successfully, it fails with this message — the post-download file discovery found nothing.","triggerScenarios":"aria2c exited 0 but wrote nothing into dest_dir (e.g. empty/redirect-only response), or dest_dir path differs from aria2c's actual save directory (relative vs absolute path, --dir mismatch), or all files still have .aria2 suffixes.","commonSituations":"URL that resolves to an empty 200 response; passing a dest_dir that doesn't match the cwd-dependent relative path aria2c used; concurrent downloads in the same dir cleaning files; aria2 saving under a different --dir option.","solutions":["Always set opts.file_name explicitly so the code does not have to guess by mtime.","Verify dest_dir is the exact same absolute directory aria2c writes to.","Check dest_dir contents for files stuck with a .aria2 control suffix (incomplete download).","Re-run and watch aria2c's stdout for the actual save path."],"exampleFix":"// before\nlet path = if !opts.file_name.trim().is_empty() { ... } else { ...ok_or_else(...)? };\n// after\nlet file_name = if opts.file_name.trim().is_empty() {\n    // derive from URL as a fallback before scanning the dir\n    url_file_name(&opts.url).ok_or_else(|| anyhow!(\"informe file_name: nao foi possivel deduzir o nome do arquivo\"))?\n} else { opts.file_name.trim().to_string() };\nlet path = PathBuf::from(&opts.dest_dir).join(file_name);","handlingStrategy":"validation","validationCode":"// antes de chamar:\nassert!(!opts.file_name.trim().is_empty(), \"informe file_name explicitamente\");\nassert!(Path::new(&opts.dest_dir).is_dir(), \"dest_dir nao existe\");","typeGuard":null,"tryCatchPattern":"match aria2::download(opts).await {\n    Err(e) if e.to_string().contains(\"nao achei o arquivo\") => {\n        eprintln!(\"defina opts.file_name para nao depender da heuristica de mtime\");\n    }\n    other => other?,\n}","preventionTips":["Always populate opts.file_name — never rely on the newest-file heuristic.","Use absolute paths for dest_dir so aria2c and the scanner agree on the directory.","Ensure only one download runs per dest_dir to avoid mtime ambiguity."],"tags":["file-not-found","aria2","download","heuristic"],"backgroundTag":"file-not-found","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}