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

Hugo Beauzée-Luyssen git at videolan.org
Thu Apr 12 13:01:17 CEST 2018


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

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

(cherry picked from commit db239beea7244793a1a0b73d02ae2afb76d0ac75)
(cherry picked from commit 1a11278e98898b094baff7b02c2ad4e48c7dcc8d)
(cherry picked from commit 34bfcde533d82829834ded86c0d23707261e404c)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 share/lua/extensions/VLSub.lua | 35 ++++++-----------------------------
 1 file changed, 6 insertions(+), 29 deletions(-)

diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 49a9c60f92..ff29e07944 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -667,7 +667,8 @@ function check_config()
   openSub.conf.dirPath = vlc.config.userdatadir()
   local subdirs = { "lua", "extensions", "userdata", "vlsub" }
   for _, dir in ipairs(subdirs) do
-    if not vlc.io.mkdir( openSub.conf.dirPath .. slash .. dir, "0700" ) then
+    local res, err = vlc.io.mkdir( openSub.conf.dirPath .. slash .. dir, "0700" )
+    if res ~= 0 and err ~= vlc.errno.EEXIST then
       vlc.msg.warn("Failed to create " .. openSub.conf.dirPath .. slash .. dir )
       return false
     end
@@ -2029,42 +2030,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 string.match(entry, "^[^%s]+.+$") then
+        table.insert(list, entry.path .. "/" .. entry.filename)
       end
     end
     return list



More information about the vlc-commits mailing list