kestra-io / kestra

:zap: Workflow Automation Platform. Orchestrate & Schedule code in any language, run anywhere, 500+ plugins. Alternative to Zapier, Rundeck, Camunda, Airflow...
https://kestra.io
Apache License 2.0
13.21k stars 1.15k forks source link

support for deleting namespace folders #4807

Open MarthaScheffler opened 2 months ago

MarthaScheffler commented 2 months ago

Feature description

enhance the DeleteFiles plugin (https://kestra.io/plugins/core/tasks/namespace/io.kestra.plugin.core.namespace.deletefiles) to also remove folders.

example flow:

id: delete_namespace_files
namespace: kestra.sandbox

tasks:
  - id: working_directory # run following tasks in the same working directory
    type: io.kestra.plugin.core.flow.WorkingDirectory
    tasks:
      - id: write_into_directory
        type: io.kestra.core.tasks.scripts.Bash
        commands:
          - mkdir test
          - echo 'test test' >> test.txt
          - cp test.txt test

      - id: upload_directory_files_into_namespace
        type: io.kestra.plugin.core.namespace.UploadFiles
        files:
          - "glob:**"
        namespace: "{{ flow.namespace }}"

  - id: wait
    type: io.kestra.plugin.core.flow.Pause # check if the files are in the namespace

  - id: delete_namespace_files
    type: io.kestra.plugin.core.namespace.DeleteFiles
    namespace: "{{ flow.namespace }}"
    files:
      - "**"
Ben8t commented 2 months ago

Thanks Martha for opening issue !

Adding complement of the current behavior: the flow shared by Martha above will actually delete all files, but the underlying folder structure created stay in place (they are empty) Goal: also remove folders when no specific files are targeted.

For example

  - id: delete_namespace_files
    type: io.kestra.plugin.core.namespace.DeleteFiles
    namespace: "{{ flow.namespace }}"
    files:
      - "my_folder/**"

Should remove all files from my_folder and the folder itself.

Maybe we want to add a flag deleteFolder: true | false to keep things explicit and not mix with glob semantic

Malaydewangan09 commented 1 month ago

Hey @Ben8t @MilosPaunovic Can I pick this up if this is still open?

MilosPaunovic commented 1 month ago

Absolutely @Malaydewangan09! :rocket:

Malaydewangan09 commented 1 month ago

Thanks @MilosPaunovic Let me summarize this once If we add a flag as suggested by @Ben8t (false by default), When the flag is set to 'true,' the folder should also be deleted if it becomes empty after its all files are removed.

Skraye commented 1 month ago

@Malaydewangan09 Hello! You get the issue!

@Ben8t I suggest we call it deleteParentFolder to avoid confusion thinking you need to enable it to delete folder in the given glob pattern