Skip to content

temp_del waits for user's input when trying to remove write-protected file #71

Open
@meleu

Description

@meleu

Issue

I faced a scenario where my test was stuck, and after a Ctrl+C I noticed it was happening because the rm command in temp_del was waiting for user's input.

Specifically this line:

if ! result="$(rm -r -- "$path" 2>&1 >/dev/null )"; then

I'm wondering if we should use rm -rf here (which probably requires extra care).

Using --interactive=never would be The Perfect™ solution, but I'm afraid it's not portable (GNU coreutils only).

Expected behavior

Given the fact that temp_del is supposed to be used programatically (never in an interactive session), it should never wait for user's input (it should either succeed or fail).

Steps to reproduce

Start a dummy project:

mkdir -p deleteme/test
cd deleteme
git init

git submodule add \
  https://github.com/bats-core/bats-file.git \
  test/test_helper/bats-file

git submodule add \
  https://github.com/bats-core/bats-support.git \
  test/test_helper/bats-support

Create a sample.bats like this:

setup() {
  load 'test/test_helper/bats-support/load'
  load 'test/test_helper/bats-file/load'

  TEST_TEMP_DIR="$(temp_make)"
}

teardown() {
  temp_del "${TEST_TEMP_DIR}"
}

@test "temp_del waits for user input" {
  cd "${TEST_TEMP_DIR}"
  mkdir my_dir
  chmod a=r my_dir
}

Run the test and see it getting stuck.

$ bats sample.bats
sample.bats
   temp_del waits for user input # 👈 Hit Ctrl+C
 ✗ temp_del waits for user input
   (from function `temp_del' in file test/test_helper/bats-file/src/temp.bash, line 1,
    from function `teardown' in test file sample.bats, line 11)
     `temp_del "${TEST_TEMP_DIR}"' failed

   -- ERROR: temp_del --
   rm: remove write-protected directory '/tmp/sample.bats-1-YgMpb7/my_dir'?
   --


   Received SIGINT, aborting ...


1 test, 1 failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions