[vlc-commits] VLSub: Stop using io.popen to list files & directories

Hugo Beauzée-Luyssen git at videolan.org
Mon Apr 9 17:02:04 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Apr  6 18:20:30 2018 +0200| [db239beea7244793a1a0b73d02ae2afb76d0ac75] | committer: Hugo Beauzée-Luyssen

VLSub: Stop using io.popen to list files & directories

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=db239beea7244793a1a0b73d02ae2afb76d0ac75
---

 share/lua/extensions/VLSub.lua | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index f26d303032..72d4e1fa3b 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -2036,42 +2036,18 @@ function file_exist(name) -- test readability
   end
 end
 
-function is_dir(path)
-  if not path or trim(path) == ""
-  then return false end
-  -- Remove slash at the end or it won't work on Windows
-  path = string.gsub(path, "^(.-)[\\/]?$", "%1")
-  local f, _, code = vlc.io.open(path, "rb")
-
-  if f then
-    _, _, code = f:read("*a")
-    if code == 21 then
-      return true
-    end
-  elseif code == 13 then
-    return true
-  end
-
-  return false
-end
-
 function list_dir(path)
   if not path or trim(path) == ""
   then return false end
   local dir_list_cmd
   local list = {}
-  if not is_dir(path) then return false end
 
-  if openSub.conf.os == "win" then
-    dir_list_cmd = io.popen('dir /b "'..path..'"')
-  elseif openSub.conf.os == "lin" then
-    dir_list_cmd = io.popen('ls -1 "'..path..'"')
-  end
+  dir_list_cmd = vlc.io.readdir(path)
 
   if dir_list_cmd then
-    for filename in dir_list_cmd:lines() do
-      if string.match(filename, "^[^%s]+.+$") then
-        table.insert(list, filename)
+    for _, entry in dir_list_cmd do
+      if not entry.isDir and string.match(entry.filename, "^[^%s]+.+$") then
+        table.insert(list, entry.filename)
       end
     end
     return list



More information about the vlc-commits mailing list