Sign up here and you can log into the forum!

duplicate files found with collectPlugins()

The place to report WDTVExt bus

duplicate files found with collectPlugins()   

Postby Darren » Wed Jul 14, 2010 2:16 am

In collectPlugins() is the following code, which is returning duplicate files from the list() method.

Code: Select all
    if (c.isDirectory) {
       var l = c.list()
       for (var idx in l) {
            var cPath = l[idx];
            Plugin.collectPlugins(cPath)
        }
    }

According to the docs on the File object, the list() method returns an array containing all the files found, and each file will be listed twice, once by numeric iterator, and once by named iterator.

To only receive one instance of each file listed, just use one iteration method or the other. But, if you use the "for(var idx in l)" technique then you will be using both iteration methods, and will receive two of each listed file.

An easy fix for this in the above code would be:

Code: Select all
    if (c.isDirectory) {
        var l = c.list()
        for (var idx=0; idx<l.length; idx++) {     // this line changed
            var cPath = l[idx];
            Plugin.collectPlugins(cPath)
        }
    }
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Re: duplicate files found with collectPlugins()   

Postby recliq » Wed Jul 14, 2010 8:46 am

the code mentioned was completely replaced by different search method in beta FW, which will be released soon.
Also the new method increases plugin collection speed. see here
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5024
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: duplicate files found with collectPlugins()   

Postby Darren » Wed Jul 14, 2010 3:10 pm

Thanks, I saw that post after I had created my own method. It took me like 10 times reading the docs for the File object before I knew what they meant about the iterators, so I thought I'd share.

Based on the original function, I stayed with a native javascript method for collecting the plugins, as compared to piping a system call.

This native method takes under 150ms to collect the plugins, no matter how many files you have on your disks. It looks like the piped method is taking much longer than this if you have lots of files, even if you use the maxdepth option.

Code: Select all
Plugin.collectPlugins = function(path, level) {
   if(!level) var level=0;
   var c = new File(path);
   var l;
   if(level==1) l = c.list(/\.plugin\.js$|^plugins$/i);
   else l = c.list();
   for (var idx=0; idx<l.length; idx++) {
      if (l[idx].isDirectory) {
         if(level<3) Plugin.collectPlugins(l[idx].path, level+1)
      }
      else if (l[idx].isFile && l[idx].name.endsWith(".plugin.js")) {
         Plugin.pluginsPath.push(l[idx].path)
      }
   }
}
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm


Return to WDTVExt bugs

Who is online

Users browsing this forum: No registered users and 1 guest