Theldus commited on
Commit
9162df9
·
unverified ·
1 Parent(s): 542accf

main : fix file existence check in main.cpp (#1889)

Browse files

In commit dda4b0e of PR #1872, I've introduced a check for the
existence of files before loading the model. However, I haven't
considered the case where whisper.cpp might read from stdin as well,
and in such cases, the checks should ignore the "-" argument as it
does not represent a regular file.

Additionally, this commit removes the usage of 'stat()' in favor of
the recently introduced function 'is_file_exist()' in common.cpp from
PR #1871.

Apologies for the bug introduced in the previous PR and any
inconvenience it may have caused.

Files changed (1) hide show
  1. examples/main/main.cpp +1 -4
examples/main/main.cpp CHANGED
@@ -10,8 +10,6 @@
10
  #include <vector>
11
  #include <cstring>
12
 
13
- #include <sys/stat.h>
14
-
15
  #if defined(_MSC_VER)
16
  #pragma warning(disable: 4244 4267) // possible loss of data
17
  #endif
@@ -845,10 +843,9 @@ int main(int argc, char ** argv) {
845
 
846
  // remove non-existent files
847
  for (auto it = params.fname_inp.begin(); it != params.fname_inp.end();) {
848
- struct stat st;
849
  const auto fname_inp = it->c_str();
850
 
851
- if (stat(fname_inp, &st) == -1) {
852
  fprintf(stderr, "error: input file not found '%s'\n", fname_inp);
853
  it = params.fname_inp.erase(it);
854
  continue;
 
10
  #include <vector>
11
  #include <cstring>
12
 
 
 
13
  #if defined(_MSC_VER)
14
  #pragma warning(disable: 4244 4267) // possible loss of data
15
  #endif
 
843
 
844
  // remove non-existent files
845
  for (auto it = params.fname_inp.begin(); it != params.fname_inp.end();) {
 
846
  const auto fname_inp = it->c_str();
847
 
848
+ if (*it != "-" && !is_file_exist(fname_inp)) {
849
  fprintf(stderr, "error: input file not found '%s'\n", fname_inp);
850
  it = params.fname_inp.erase(it);
851
  continue;