ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Improvement]: Add directory content validation for `bal clean --target-dir <path>` option

Open Thushara-Piyasekara opened this issue 9 months ago • 0 comments

Description

As of now it is possible to delete any directory and its contents using bal clean --target-dir <path> command. Following is the emitted output for bal clean --help command,

SYNOPSIS
       bal clean [OPTIONS]


DESCRIPTION
       Remove the 'target' directory created during the build. This will delete
       all files and directories in the target directory.

       The default target directory that will be cleaned is the
       '<package-root>/target'. You may also provide a custom target to be
       cleaned.


OPTIONS
       --target-dir <path>
           Target directory path.

EXAMPLES
       Clean the default target directory of the current package.
           $ bal clean

       Clean the provided target directory.
           $ bal clean <target-directory-path>

Describe your problem(s)

Since the help description says, Remove the 'target' directory created during the build, the bal clean command should be limited to ballerina related directories. Some users might mistakenly provide the project directory instead of the target directory for the bal clean --target-dir <path> and get the project directory deleted.

Describe your solution(s)

It is possible to do a content validation before deleting the provided directory. We can check whether a bin\ directory is present inside the given target directory. If such a directory is not present or if there are unrecognized subdirectories we can halt the deletion and ask for verification in the CLI.

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Thushara-Piyasekara avatar May 06 '24 05:05 Thushara-Piyasekara