Changes of Revision 50

kodi-next.spec Changed
x
 
1
@@ -80,8 +80,8 @@
2
 BuildRequires:  fdupes
3
 BuildRequires:  gawk
4
 # need gcc5
5
-BuildRequires:  gcc5 
6
-BuildRequires:  gcc5-c++
7
+BuildRequires:  gcc
8
+BuildRequires:  gcc-c++
9
 BuildRequires:  libtool
10
 BuildRequires:  pkg-config
11
 BuildRequires:  pkgconfig(python2)
12
_service:download_files:master.tar.gz/xbmc/platform/Filesystem.h Changed
15
 
1
@@ -33,7 +33,11 @@
2
   std::uintmax_t available;
3
 };
4
 
5
-space_info space(const std::string& path, std::error_code& ec);
6
+space_info space(const std::string &path, std::error_code &ec);
7
+
8
+std::string temp_directory_path(std::error_code &ec);
9
+std::string create_temp_directory(std::error_code &ec);
10
+std::string temp_file_path(std::string suffix, std::error_code &ec);
11
 }
12
 }
13
 }
14
\ No newline at end of file
15
_service:download_files:master.tar.gz/xbmc/platform/posix/Filesystem.cpp Changed
89
 
1
@@ -21,6 +21,7 @@
2
 #include "platform/Filesystem.h"
3
 #include "system.h"
4
 #include "filesystem/SpecialProtocol.h"
5
+#include "utils/URIUtils.h"
6
 
7
 #if defined(TARGET_LINUX)
8
 #include <sys/statvfs.h>
9
@@ -31,6 +32,9 @@
10
 #include <sys/statfs.h>
11
 #endif
12
 
13
+#include <cstdlib>
14
+#include <limits.h>
15
+
16
 namespace KODI
17
 {
18
 namespace PLATFORM
19
@@ -65,6 +69,67 @@
20
 
21
   return sp;
22
 }
23
+
24
+std::string temp_directory_path(std::error_code &ec)
25
+{
26
+  ec.clear();
27
+
28
+  auto result = getenv("TMPDIR");
29
+  if (result)
30
+    return URIUtils::AppendSlash(result);
31
+
32
+  return "/tmp/";
33
+}
34
+
35
+std::string create_temp_directory(std::error_code &ec)
36
+{
37
+  char buf[PATH_MAX];
38
+
39
+  auto path = temp_directory_path(ec);
40
+
41
+  strcpy(buf, (path + "xbmctempXXXXXX").c_str());
42
+
43
+  auto tmp = mkdtemp(buf);
44
+  if (!tmp)
45
+  {
46
+    ec.assign(errno, std::system_category());
47
+    return std::string();
48
+  }
49
+  
50
+  ec.clear();
51
+  return std::string(tmp);
52
+}
53
+
54
+std::string temp_file_path(std::string suffix, std::error_code &ec)
55
+{
56
+  char tmp[PATH_MAX];
57
+
58
+  auto tempPath = create_temp_directory(ec);
59
+  if (ec)
60
+    return std::string();
61
+
62
+  tempPath = URIUtils::AddFileToFolder(tempPath, "xbmctempfileXXXXXX" + suffix);
63
+  if (tempPath.length() >= PATH_MAX)
64
+  {
65
+    ec.assign(EOVERFLOW, std::system_category());
66
+    return std::string();
67
+  }
68
+
69
+  strcpy(tmp, tempPath.c_str());
70
+
71
+  auto fd = mkstemps(tmp, suffix.length());
72
+  if (fd < 0)
73
+  {
74
+    ec.assign(errno, std::system_category());
75
+    return std::string();
76
+  }
77
+
78
+  close(fd);
79
+
80
+  ec.clear();
81
+  return std::string(tmp);
82
+}
83
+
84
+}
85
 }
86
 }
87
-}
88
\ No newline at end of file
89
_service:download_files:master.tar.gz/xbmc/platform/win32/Filesystem.cpp Changed
94
 
1
@@ -26,6 +26,8 @@
2
 #endif
3
 #include <Windows.h>
4
 
5
+namespace win = KODI::PLATFORM::WINDOWS;
6
+
7
 namespace KODI
8
 {
9
 namespace PLATFORM
10
@@ -34,11 +36,10 @@
11
 {
12
 space_info space(const std::string& path, std::error_code& ec)
13
 {
14
-  using WINDOWS::ToW;
15
 
16
   ec.clear();
17
   space_info sp;
18
-  auto pathW = ToW(path);
19
+  auto pathW = win::ToW(path);
20
 
21
   ULARGE_INTEGER capacity;
22
   ULARGE_INTEGER available;
23
@@ -60,6 +61,69 @@
24
 
25
   return sp;
26
 }
27
+
28
+std::string temp_directory_path(std::error_code &ec)
29
+{
30
+  wchar_t lpTempPathBuffer[MAX_PATH + 1];
31
+
32
+  if (!GetTempPathW(MAX_PATH, lpTempPathBuffer))
33
+  {
34
+    ec.assign(GetLastError(), std::system_category());
35
+    return std::string();
36
+  }
37
+
38
+  ec.clear();
39
+  return win::FromW(lpTempPathBuffer);
40
+}
41
+
42
+std::string create_temp_directory(std::error_code &ec)
43
+{
44
+  wchar_t lpTempPathBuffer[MAX_PATH + 1];
45
+
46
+  std::wstring xbmcTempPath = win::ToW(temp_directory_path(ec));
47
+
48
+  if (ec)
49
+    return std::string();
50
+
51
+  if (!GetTempFileNameW(xbmcTempPath.c_str(), L"xbm", 0, lpTempPathBuffer))
52
+  {
53
+    ec.assign(GetLastError(), std::system_category());
54
+    return std::string();
55
+  }
56
+
57
+  DeleteFileW(lpTempPathBuffer);
58
+
59
+  if (!CreateDirectoryW(lpTempPathBuffer, nullptr))
60
+  {
61
+    ec.assign(GetLastError(), std::system_category());
62
+    return std::string();
63
+  }
64
+
65
+  ec.clear();
66
+  return win::FromW(lpTempPathBuffer);
67
+}
68
+
69
+std::string temp_file_path(std::string, std::error_code &ec)
70
+{
71
+  wchar_t lpTempPathBuffer[MAX_PATH + 1];
72
+
73
+  std::wstring xbmcTempPath = win::ToW(create_temp_directory(ec));
74
+
75
+  if (ec)
76
+    return std::string();
77
+
78
+  if (!GetTempFileNameW(xbmcTempPath.c_str(), L"xbm", 0, lpTempPathBuffer))
79
+  {
80
+    ec.assign(GetLastError(), std::system_category());
81
+    return std::string();
82
+  }
83
+
84
+  DeleteFileW(lpTempPathBuffer);
85
+
86
+  ec.clear();
87
+  return win::FromW(lpTempPathBuffer);
88
+}
89
+
90
 }
91
 }
92
 }
93
\ No newline at end of file
94
_service:download_files:master.tar.gz/xbmc/test/TestBasicEnvironment.cpp Changed
77
 
1
@@ -29,11 +29,7 @@
2
 #include "Application.h"
3
 #include "AppParamParser.h"
4
 #include "windowing/WinSystem.h"
5
-
6
-#if defined(TARGET_WINDOWS)
7
-#include "platform/win32/WIN32Util.h"
8
-#include "platform/win32/CharsetConverter.h"
9
-#endif
10
+#include "platform/Filesystem.h"
11
 
12
 #ifdef TARGET_DARWIN
13
 #include "Util.h"
14
@@ -42,6 +38,9 @@
15
 #include <cstdio>
16
 #include <cstdlib>
17
 #include <climits>
18
+#include <system_error>
19
+
20
+namespace fs = KODI::PLATFORM::FILESYSTEM;
21
 
22
 void TestBasicEnvironment::SetUp()
23
 {
24
@@ -74,29 +73,19 @@
25
   /* Create a temporary directory and set it to be used throughout the
26
    * test suite run.
27
    */
28
-#ifdef TARGET_WINDOWS
29
-  using KODI::PLATFORM::WINDOWS::FromW;
30
-  std::wstring xbmcTempPath;
31
-  TCHAR lpTempPathBuffer[MAX_PATH];
32
-  if (!GetTempPath(MAX_PATH, lpTempPathBuffer))
33
-    SetUpError();
34
-  xbmcTempPath = lpTempPathBuffer;
35
-  if (!GetTempFileName(xbmcTempPath.c_str(), L"xbmctempdir", 0, lpTempPathBuffer))
36
-    SetUpError();
37
-  DeleteFile(lpTempPathBuffer);
38
-  if (!CreateDirectory(lpTempPathBuffer, NULL))
39
-    SetUpError();
40
-  CSpecialProtocol::SetTempPath(FromW(lpTempPathBuffer));
41
-  CSpecialProtocol::SetProfilePath(FromW(lpTempPathBuffer));
42
-#else
43
-  char buf[MAX_PATH];
44
-  char *tmp;
45
-  strcpy(buf, "/tmp/xbmctempdirXXXXXX");
46
-  if ((tmp = mkdtemp(buf)) == NULL)
47
+
48
+  g_application.EnablePlatformDirectories(false);
49
+
50
+  std::error_code ec;
51
+  m_tempPath = fs::create_temp_directory(ec);
52
+  if (ec)
53
+  {
54
+    TearDown();
55
     SetUpError();
56
-  CSpecialProtocol::SetTempPath(tmp);
57
-  CSpecialProtocol::SetProfilePath(tmp);
58
-#endif
59
+  }
60
+
61
+  CSpecialProtocol::SetTempPath(m_tempPath);
62
+  CSpecialProtocol::SetProfilePath(m_tempPath);
63
 
64
   /* Create and delete a tempfile to initialize the VFS (really to initialize
65
    * CLibcdio). This is done so that the initialization of the VFS does not
66
@@ -120,8 +109,8 @@
67
 
68
 void TestBasicEnvironment::TearDown()
69
 {
70
-  std::string xbmcTempPath = CSpecialProtocol::TranslatePath("special://temp/");
71
-  XFILE::CDirectory::Remove(xbmcTempPath);
72
+  XFILE::CDirectory::RemoveRecursive(m_tempPath);
73
+
74
   CServiceBroker::GetSettings().Uninitialize();
75
   g_application.m_ServiceManager->DeinitTesting();
76
 }
77
_service:download_files:master.tar.gz/xbmc/test/TestBasicEnvironment.h Changed
16
 
1
@@ -21,6 +21,8 @@
2
 
3
 #include "gtest/gtest.h"
4
 
5
+#include <string>
6
+
7
 class TestBasicEnvironment : public testing::Environment
8
 {
9
 public:
10
@@ -28,4 +30,5 @@
11
   void TearDown() override;
12
 private:
13
   void SetUpError();
14
+  std::string m_tempPath;
15
 };
16
_service:download_files:master.tar.gz/xbmc/test/TestUtils.cpp Changed
77
 
1
@@ -22,7 +22,7 @@
2
 #include "Util.h"
3
 #include "filesystem/File.h"
4
 #include "filesystem/SpecialProtocol.h"
5
-#include "platform/win32/CharsetConverter.h"
6
+#include "platform/Filesystem.h"
7
 #include "utils/StringUtils.h"
8
 #include "utils/URIUtils.h"
9
 
10
@@ -34,6 +34,10 @@
11
 #include <ctime>
12
 #endif
13
 
14
+#include <system_error>
15
+
16
+namespace fs = KODI::PLATFORM::FILESYSTEM;
17
+
18
 class CTempFile : public XFILE::CFile
19
 {
20
 public:
21
@@ -44,38 +48,13 @@
22
   }
23
   bool Create(const std::string &suffix)
24
   {
25
-    char tmp[MAX_PATH];
26
-
27
-    m_ptempFileDirectory = CSpecialProtocol::TranslatePath("special://temp/");
28
-    m_ptempFilePath = m_ptempFileDirectory + "xbmctempfileXXXXXX";
29
-    m_ptempFilePath += suffix;
30
-    if (m_ptempFilePath.length() >= MAX_PATH)
31
-    {
32
-      m_ptempFilePath = "";
33
+    std::error_code ec;
34
+    m_ptempFilePath = fs::temp_file_path(suffix, ec);
35
+    if (ec)
36
       return false;
37
-    }
38
-    strcpy(tmp, m_ptempFilePath.c_str());
39
 
40
-#ifdef TARGET_WINDOWS
41
-    using namespace KODI::PLATFORM::WINDOWS;
42
-    wchar_t tmpW[MAX_PATH];
43
-    if (!GetTempFileName(ToW(CSpecialProtocol::TranslatePath("special://temp/")).c_str(),
44
-                         L"xbmctempfile", 0, tmpW))
45
-    {
46
-      m_ptempFilePath = "";
47
+    if (m_ptempFilePath.empty())
48
       return false;
49
-    }
50
-    m_ptempFilePath = FromW(tmpW);
51
-#else
52
-    int fd;
53
-    if ((fd = mkstemps(tmp, suffix.length())) < 0)
54
-    {
55
-      m_ptempFilePath = "";
56
-      return false;
57
-    }
58
-    close(fd);
59
-    m_ptempFilePath = tmp;
60
-#endif
61
 
62
     OpenForWrite(m_ptempFilePath.c_str(), true);
63
     return true;
64
@@ -91,11 +70,10 @@
65
   }
66
   std::string getTempFileDirectory() const
67
   {
68
-    return m_ptempFileDirectory;
69
+    return URIUtils::GetDirectory(m_ptempFilePath);
70
   }
71
 private:
72
   std::string m_ptempFilePath;
73
-  std::string m_ptempFileDirectory;
74
 };
75
 
76
 CXBMCTestUtils::CXBMCTestUtils()
77
_service:download_files:master.tar.gz/xbmc/utils/Literals.h Added
43
 
1
@@ -0,0 +1,40 @@
2
+#pragma once
3
+/*
4
+ *      Copyright (C) 2014 Team XBMC
5
+ *      http://xbmc.org
6
+ *
7
+ *  This Program is free software; you can redistribute it and/or modify
8
+ *  it under the terms of the GNU General Public License as published by
9
+ *  the Free Software Foundation; either version 2, or (at your option)
10
+ *  any later version.
11
+ *
12
+ *  This Program is distributed in the hope that it will be useful,
13
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ *  GNU General Public License for more details.
16
+ *
17
+ *  You should have received a copy of the GNU General Public License
18
+ *  along with XBMC; see the file COPYING.  If not, see
19
+ *  <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+constexpr unsigned long long int operator"" _kib (unsigned long long int val)
24
+{
25
+    return val * 1024ull;
26
+}
27
+
28
+constexpr unsigned long long int operator"" _kb (unsigned long long int val)
29
+{
30
+    return val * 1000ull;
31
+}
32
+
33
+constexpr unsigned long long int operator"" _mib (unsigned long long int val)
34
+{
35
+    return val * 1024ull * 1024ull;
36
+}
37
+
38
+constexpr unsigned long long int operator"" _mb (unsigned long long int val)
39
+{
40
+    return val * 1000ull * 1000ull;
41
+}
42
\ No newline at end of file
43
_service:download_files:master.tar.gz/xbmc/utils/URIUtils.cpp Changed
14
 
1
@@ -1087,6 +1087,12 @@
2
   return false;
3
 }
4
 
5
+std::string URIUtils::AppendSlash(std::string strFolder)
6
+{
7
+  AddSlashAtEnd(strFolder);
8
+  return strFolder;
9
+}
10
+
11
 void URIUtils::AddSlashAtEnd(std::string& strFolder)
12
 {
13
   if (IsURL(strFolder))
14
_service:download_files:master.tar.gz/xbmc/utils/URIUtils.h Changed
9
 
1
@@ -166,6 +166,7 @@
2
   static bool IsPVRGuideItem(const std::string& strFile);
3
   static bool IsUsingFastSwitch(const std::string& strFile);
4
 
5
+  static std::string AppendSlash(std::string strFolder);
6
   static void AddSlashAtEnd(std::string& strFolder);
7
   static bool HasSlashAtEnd(const std::string& strFile, bool checkURL = false);
8
   static void RemoveSlashAtEnd(std::string& strFolder);
9