Skip to content

Commit

Permalink
Always reread the entire MARKUT file every second in watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Dec 21, 2023
1 parent 3ab986e commit 50f5995
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions markut.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,65 +899,38 @@ func watchSubcommand(args []string) bool {
}

for {
initialStat, err := os.Stat(*markutPtr)
if err != nil {
fmt.Printf("ERROR: could not stat %s: %s", *markutPtr, err)
return false
}
// NOTE: always use rsync(1) for updating the MARKUT file remotely.
// This kind of crappy modification checking needs at least some sort of atomicity.
// rsync(1) is as atomic as rename(2). So it's alright for majority of the cases.

context, ok := evalMarkutFile(*markutPtr)
if !ok {
return false
}

for _, chunk := range(context.chunks) {
if !chunk.Unfinished {
if _, err := os.Stat(chunk.Name()); errors.Is(err, os.ErrNotExist) {
err = ffmpegCutChunk(context, chunk, *yPtr)
if err != nil {
fmt.Printf("ERROR: Could not cut the chunk %s: %s\n", chunk.Name(), err)
return false
}
break
}
}
}

// TODO: properly check if everything is finished
done := true
for _, chunk := range(context.chunks) {
if chunk.Unfinished {
done = false
break
continue
}

if _, err := os.Stat(chunk.Name()); errors.Is(err, os.ErrNotExist) {
err = ffmpegCutChunk(context, chunk, *yPtr)
if err != nil {
fmt.Printf("ERROR: Could not cut the chunk %s: %s\n", chunk.Name(), err)
return false
}
done = false
break
}
}

if done {
break;
break
}

// NOTE: always use rsync(1) for updating the MARKUT file remotely.
// This kind of crappy modification checking needs at least some sort of atomicity.
// rsync(1) is as atomic as rename(2). So it's alright for majority of the cases.
fmt.Printf("INFO: %s is not done. Waiting for modifications...\n", *markutPtr);
for {
time.Sleep(1 * time.Second)

stat, err := os.Stat(*markutPtr)
if err != nil {
fmt.Printf("ERROR: could not stat %s: %s\n", *markutPtr, err)
continue
}

if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() {
break
}
}
time.Sleep(1 * time.Second)
}

context, ok := evalMarkutFile(*markutPtr)
Expand Down

0 comments on commit 50f5995

Please sign in to comment.