Skip to content

Unexpected rm -rf /* will remove all files in home #20

@Yixun-Hu

Description

@Yixun-Hu

The bash file of

for i in 0 3 4 6 16 21 22; do 
  # need to download the data cd $CODA_ROOT_DIR/.. 
  python scripts/download_split.py -d ./data -t sequence -se $i <<< "Y" 
  # need to process the data cd $REMEMBR_PATH 
  python scripts/preprocess_coda.py -s $i 
  # delete original data 
  rm -rf $CODA_ROOT_DIR/* 
done

is dangerous if $CODA_ROOT_DIR is blank. Then this command will delete all files under home. A safer version:

#!/usr/bin/env bash
set -euo pipefail          # if not set then quit
shopt -s failglob         

: "${CODA_ROOT_DIR:?set CODA_ROOT_DIR to /path/to/coda-devkit/data}"
: "${REMEMBR_PATH:?set REMEMBR_PATH to /path/to/remembr}"

CODA_ROOT_DIR="$(readlink -f "$CODA_ROOT_DIR")"
case "$CODA_ROOT_DIR" in
  /|/home|"$HOME"|/home/*) echo "Refusing to operate on $CODA_ROOT_DIR"; exit 1;;
esac

for i in 0 3 4 6 16 21 22; do
  cd "$CODA_ROOT_DIR/.." || exit 1
  python scripts/download_split.py -d ./data -t sequence -se "$i" <<< "Y"

  cd "$REMEMBR_PATH" || exit 1
  python scripts/preprocess_coda.py -s "$i"

  find "$CODA_ROOT_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions