From fb58bfbb6a87666d35fde23ff08cf9a47071e188 Mon Sep 17 00:00:00 2001
From: Stefan Saraev <stefan@saraev.ca>
Date: Mon, 2 Mar 2015 23:50:40 +0200
Subject: [PATCH 05/12] make binary addons executable

add executable mode to all files in addon's bin folder

credits to vpeter4 for the patch
---
 xbmc/addons/Addon.cpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/xbmc/addons/Addon.cpp b/xbmc/addons/Addon.cpp
index bf5c584..03325dd 100644
--- a/xbmc/addons/Addon.cpp
+++ b/xbmc/addons/Addon.cpp
@@ -44,6 +44,10 @@
 #include <string.h>
 #include <ostream>
 
+#include <iostream>
+#include <dirent.h>
+#include <sys/stat.h>
+
 using XFILE::CDirectory;
 using XFILE::CFile;
 using namespace std;
@@ -674,6 +678,28 @@ void OnPostInstall(const AddonPtr& addon, bool update, bool modal)
   if (CAddonMgr::Get().GetAddon(addon->ID(), localAddon, ADDON_CONTEXT_ITEM))
     CContextMenuManager::Get().Register(std::static_pointer_cast<CContextItemAddon>(localAddon));
 
+  // OE: make binary addons executable, creddits to vpeter4
+  std::string addonDirPath;
+  std::string chmodFilePath;
+  DIR *addonsDir;
+  struct dirent *fileDirent;
+  struct stat fileStat;
+  int statRet;
+
+  addonDirPath = "/storage/.kodi/addons/" + addon->ID() + "/bin/";
+  if ((addonsDir = opendir(addonDirPath.c_str())) != NULL)
+  {
+    while ((fileDirent = readdir(addonsDir)) != NULL)
+    {
+      chmodFilePath = addonDirPath + fileDirent->d_name;
+      statRet = stat(chmodFilePath.c_str(), &fileStat);
+      if (statRet == 0 && (fileStat.st_mode & S_IFMT) != S_IFDIR)
+        chmod(chmodFilePath.c_str(), fileStat.st_mode | S_IXUSR | S_IXGRP | S_IXOTH);
+    }
+    closedir(addonsDir);
+  }
+  // OE
+
   addon->OnPostInstall(update, modal);
 }
 
-- 
2.1.4

