mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
some refactoring + made browse-walk draw a dir in sync (fixed unstable ordering)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
08cb529fc3
commit
bebfe3131e
@ -91,6 +91,18 @@ function(path, make){
|
|||||||
// XXX expose these as config...
|
// XXX expose these as config...
|
||||||
var fullpath = false
|
var fullpath = false
|
||||||
|
|
||||||
|
// sync version of stat...
|
||||||
|
var stat = function(path){
|
||||||
|
return new Promise(function(resolve, reject){
|
||||||
|
try {
|
||||||
|
resolve(fs.statSync(path))
|
||||||
|
} catch(err){
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
var stat = function(path){
|
var stat = function(path){
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function(resolve, reject){
|
||||||
fs.stat.call(fs, path, function(err, res){
|
fs.stat.call(fs, path, function(err, res){
|
||||||
@ -98,6 +110,7 @@ function(path, make){
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// get the drive list on windows...
|
// get the drive list on windows...
|
||||||
if(os.type() == 'Windows_NT' && path == '/'){
|
if(os.type() == 'Windows_NT' && path == '/'){
|
||||||
@ -164,48 +177,51 @@ function(path, make){
|
|||||||
make(fullpath ? path + '../' : '../'))
|
make(fullpath ? path + '../' : '../'))
|
||||||
}
|
}
|
||||||
|
|
||||||
files.map(function(file){
|
// XXX split out the making stage after the stat stage to
|
||||||
return stat(path +'/'+ file)
|
// be able to sort suff correctly...
|
||||||
.catch(function(err){
|
files
|
||||||
make(fullpath
|
.map(function(file){
|
||||||
? path +'/'+ file
|
return stat(path +'/'+ file)
|
||||||
: file, null, true)
|
.catch(function(err){
|
||||||
})
|
|
||||||
.then(function(res){
|
|
||||||
// can't read stat... (XXX ???)
|
|
||||||
if(res == null){
|
|
||||||
make(fullpath
|
make(fullpath
|
||||||
? path +'/'+ file
|
? path +'/'+ file
|
||||||
: file, null, true)
|
: file, null, true)
|
||||||
return
|
})
|
||||||
}
|
.then(function(res){
|
||||||
|
// can't read stat... (XXX ???)
|
||||||
|
if(res == null){
|
||||||
|
make(fullpath
|
||||||
|
? path +'/'+ file
|
||||||
|
: file, null, true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var dir = res.isDirectory()
|
var dir = res.isDirectory()
|
||||||
var elem = res && make(fullpath
|
var elem = res && make(fullpath
|
||||||
? path +'/'+ file
|
? path +'/'+ file
|
||||||
: file + (dir ? '/' : ''),
|
: file + (dir ? '/' : ''),
|
||||||
null,
|
null,
|
||||||
that.options.disableFiles && !dir)
|
that.options.disableFiles && !dir)
|
||||||
|
|
||||||
// count the number of files...
|
// count the number of files...
|
||||||
// NOTE: we do not care how long it will take
|
// NOTE: we do not care how long it will take
|
||||||
// so we'll not wait...
|
// so we'll not wait...
|
||||||
res && dir && _countDirFiles(path, file, elem)
|
res && dir && _countDirFiles(path, file, elem)
|
||||||
})
|
})
|
||||||
// NOTE: we are not using promise.all(..) here because it
|
// NOTE: we are not using promise.all(..) here because it
|
||||||
// triggers BEFORE the first make(..) is called...
|
// triggers BEFORE the first make(..) is called...
|
||||||
// ...not sure I fully understand why...
|
// ...not sure I fully understand why...
|
||||||
.then(function(){
|
.then(function(){
|
||||||
// NOTE: this will get called for all results
|
// NOTE: this will get called for all results
|
||||||
// including ones that generate errors, not
|
// including ones that generate errors, not
|
||||||
// sure if this is a bug in .denodeify(..)
|
// sure if this is a bug in .denodeify(..)
|
||||||
// or by-design though...
|
// or by-design though...
|
||||||
res.push(file)
|
res.push(file)
|
||||||
if(res.length == files.length){
|
if(res.length == files.length){
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user