Git Product home page Git Product logo

Comments (4)

humphd avatar humphd commented on July 22, 2024 1

Ah, you're right. If node doesn't, let's not do it either, and leave ls for this case.

from filer.

humphd avatar humphd commented on July 22, 2024

Nice find.

We sort of have code to do this already in the shell, but it could be ported into the implementation for when { recursive: true } is present, see

filer/src/shell/shell.js

Lines 205 to 280 in 75f2a70

/**
* Get the listing of a directory, returning an array of
* file entries in the following form:
*
* {
* path: <String> the basename of the directory entry
* links: <Number> the number of links to the entry
* size: <Number> the size in bytes of the entry
* modified: <Number> the last modified date/time
* type: <String> the type of the entry
* contents: <Array> an optional array of child entries
* }
*
* By default ls() gives a shallow listing. If you want
* to follow directories as they are encountered, use
* the `recursive=true` option.
*/
Shell.prototype.ls = function(dir, options, callback) {
var sh = this;
var fs = sh.fs;
if(typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
callback = callback || function(){};
if(!dir) {
callback(new Errors.EINVAL('Missing dir argument'));
return;
}
function list(path, callback) {
var pathname = Path.resolve(sh.pwd(), path);
var result = [];
fs.readdir(pathname, function(error, entries) {
if(error) {
callback(error);
return;
}
function getDirEntry(name, callback) {
name = Path.join(pathname, name);
fs.stat(name, function(error, stats) {
if(error) {
callback(error);
return;
}
var entry = stats;
if(options.recursive && stats.type === 'DIRECTORY') {
list(Path.join(pathname, entry.name), function(error, items) {
if(error) {
callback(error);
return;
}
entry.contents = items;
result.push(entry);
callback();
});
} else {
result.push(entry);
callback();
}
});
}
async.eachSeries(entries, getDirEntry, function(error) {
callback(error, result);
});
});
}
list(dir, callback);
};
.

from filer.

bcheidemann avatar bcheidemann commented on July 22, 2024

Nice find.

We sort of have code to do this already in the shell, but it could be ported into the implementation for when { recursive: true } is present, see

filer/src/shell/shell.js

Lines 205 to 280 in 75f2a70

/**
* Get the listing of a directory, returning an array of
* file entries in the following form:
*
* {
* path: <String> the basename of the directory entry
* links: <Number> the number of links to the entry
* size: <Number> the size in bytes of the entry
* modified: <Number> the last modified date/time
* type: <String> the type of the entry
* contents: <Array> an optional array of child entries
* }
*
* By default ls() gives a shallow listing. If you want
* to follow directories as they are encountered, use
* the `recursive=true` option.
*/
Shell.prototype.ls = function(dir, options, callback) {
var sh = this;
var fs = sh.fs;
if(typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
callback = callback || function(){};
if(!dir) {
callback(new Errors.EINVAL('Missing dir argument'));
return;
}
function list(path, callback) {
var pathname = Path.resolve(sh.pwd(), path);
var result = [];
fs.readdir(pathname, function(error, entries) {
if(error) {
callback(error);
return;
}
function getDirEntry(name, callback) {
name = Path.join(pathname, name);
fs.stat(name, function(error, stats) {
if(error) {
callback(error);
return;
}
var entry = stats;
if(options.recursive && stats.type === 'DIRECTORY') {
list(Path.join(pathname, entry.name), function(error, items) {
if(error) {
callback(error);
return;
}
entry.contents = items;
result.push(entry);
callback();
});
} else {
result.push(entry);
callback();
}
});
}
async.eachSeries(entries, getDirEntry, function(error) {
callback(error, result);
});
});
}
list(dir, callback);
};

.

Happy to update PR #778 to include the required changes but may not have time until next weekend. Looks like node supports encoding and withFileTypes options but not recursive for readdir. Do you want to implement it with support for recursive anyway?

from filer.

bcheidemann avatar bcheidemann commented on July 22, 2024

Nice find.
We sort of have code to do this already in the shell, but it could be ported into the implementation for when { recursive: true } is present, see

filer/src/shell/shell.js

Lines 205 to 280 in 75f2a70

/**
* Get the listing of a directory, returning an array of
* file entries in the following form:
*
* {
* path: <String> the basename of the directory entry
* links: <Number> the number of links to the entry
* size: <Number> the size in bytes of the entry
* modified: <Number> the last modified date/time
* type: <String> the type of the entry
* contents: <Array> an optional array of child entries
* }
*
* By default ls() gives a shallow listing. If you want
* to follow directories as they are encountered, use
* the `recursive=true` option.
*/
Shell.prototype.ls = function(dir, options, callback) {
var sh = this;
var fs = sh.fs;
if(typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
callback = callback || function(){};
if(!dir) {
callback(new Errors.EINVAL('Missing dir argument'));
return;
}
function list(path, callback) {
var pathname = Path.resolve(sh.pwd(), path);
var result = [];
fs.readdir(pathname, function(error, entries) {
if(error) {
callback(error);
return;
}
function getDirEntry(name, callback) {
name = Path.join(pathname, name);
fs.stat(name, function(error, stats) {
if(error) {
callback(error);
return;
}
var entry = stats;
if(options.recursive && stats.type === 'DIRECTORY') {
list(Path.join(pathname, entry.name), function(error, items) {
if(error) {
callback(error);
return;
}
entry.contents = items;
result.push(entry);
callback();
});
} else {
result.push(entry);
callback();
}
});
}
async.eachSeries(entries, getDirEntry, function(error) {
callback(error, result);
});
});
}
list(dir, callback);
};

.

Happy to update PR #778 to include the required changes but may not have time until next weekend. Looks like node supports encoding and withFileTypes options but not recursive for readdir. Do you want to implement it with support for recursive anyway?

@humphd added a skip as you suggested here. I'll make a new PR for the fixes if you want to merge #778

from filer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.