HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/fintechfuel/node_modules/sander/src/extraMethods/lsr.js
import * as fs from 'fs';
import { resolve, sep } from 'path';
import resolvePath from '../utils/resolvePath';

function walk ( dir, callback ) {
	let results = [];

	fs.readdir( dir, ( err, files ) => {
		if ( err ) return callback( err );

		let pending = files.length;
		if ( !pending ) return callback( null, results );

		files.forEach( file => {
			file = resolve( dir, file );

			fs.stat( file, ( err, stats ) => {
				if ( stats && stats.isDirectory() ) {
					walk( file, ( err, res ) => {
						results = results.concat( res );
						if ( !--pending ) callback( null, results );
					});
				} else {
					results.push( file );
					if ( !--pending ) callback( null, results );
				}
			});
		});
	});
};

export function lsr () {
	const basedir = resolvePath( arguments );

	return new Promise( ( fulfil, reject ) => {
		walk( basedir, function ( err, result ) {
			if ( err ) return reject( err );

			// files should be relative to basedir
			const index = basedir.length + 1;
			let i = result.length;
			while ( i-- ) {
				result[i] = result[i].substring( index );
			}

			fulfil( result );
		});
	});
}

export function lsrSync () {
	const basedir = resolvePath( arguments );

	let result = [];

	function processdir ( dir ) {
		fs.readdirSync( dir ).forEach( file => {
			const filepath = dir + sep + file;

			if ( fs.statSync( filepath ).isDirectory() ) {
				processdir( filepath );
			} else {
				result.push( filepath.replace( basedir + sep, '' ) );
			}
		});
	}

	processdir( basedir );
	return result;
}