import { stat } from "fs" ; import { callback } from "awaiting" ; import { exec } from "./api" ; import { get_listings_table } from "../sync/listings" ; import { deleted_file_variations } from "@cocalc/util/delete-files" ; import { pathExists } from "fs-extra" ; export async function delete_files ( paths , logger ) { logger . debug ( `delete_files ${ JSON . stringify ( paths ) }` ) ; const listings = get_listings_table ( ) ; if ( listings != null ) { for ( const path of paths ) { await listings . set_deleted ( path ) ; } } let extra = [ ] ; for ( const path of paths ) { try { const s = await callback ( stat , path ) ; if ( ! s . isDirectory ( ) ) { for ( const variation of deleted_file_variations ( path ) ) { if ( await pathExists ( variation ) ) { if ( listings != null ) { await listings . set_deleted ( variation ) ; } extra . push ( variation ) ; } } } } catch ( _err ) { } } await exec ( { command : "rm" , timeout : 60 , args : [ "-rf" , "--" ] . concat ( paths ) . concat ( extra ) , } ) ; }