summaryrefslogtreecommitdiff
blob: eb8e092c5d7adef62c058b96922f5ce0008ce364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From ad37afce28083fad7f79467b3ffdead753584358 Mon Sep 17 00:00:00 2001
From: Florent Rougon <f.rougon@frougon.net>
Date: Tue, 21 Jan 2025 00:31:22 +0100
Subject: [PATCH] NasalSGPath: move checkIORules() to
 SGPath::NasalIORulesChecker()

This allows the from_nasal_helper() in SimGear that constructs SGPath
instances from Nasal scalars to use SGPath::NasalIORulesChecker() as a
PermissionChecker.
---
 src/Scripting/NasalSGPath.cxx | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/Scripting/NasalSGPath.cxx b/src/Scripting/NasalSGPath.cxx
index 92abbbe873..d5f49d8922 100644
--- a/src/Scripting/NasalSGPath.cxx
+++ b/src/Scripting/NasalSGPath.cxx
@@ -30,28 +30,12 @@
 typedef std::shared_ptr<SGPath> SGPathRef;
 typedef nasal::Ghost<SGPathRef> NasalSGPath;
 
-SGPath::Permissions checkIORules(const SGPath& path)
-{
-  SGPath::Permissions perm;
-  if (!path.isAbsolute()) {
-    // SGPath caches permissions, which breaks for relative paths
-    // if the current directory changes
-    SG_LOG(SG_NASAL, SG_ALERT, "os.path: file operation on '" <<
-        path<< "' access denied (relative paths not accepted; use "
-        "realpath() to make a path absolute)");
-  }
-
-  perm.read  = path.isAbsolute() && !SGPath(path).validate(false).isNull();
-  perm.write = path.isAbsolute() && !SGPath(path).validate(true).isNull();
-
-  return perm;
-}
-
 // TODO make exposing such function easier...
 static naRef validatedPathToNasal( const nasal::CallContext& ctx,
                                    const SGPath& p )
 {
-  return ctx.to_nasal( SGPathRef(new SGPath(p.utf8Str(), &checkIORules)) );
+    return ctx.to_nasal(SGPathRef(new SGPath(p.utf8Str(),
+                                             &SGPath::NasalIORulesChecker)));
 }
 
 /**
@@ -78,7 +62,8 @@ static void f_path_set(SGPath& p, const nasal::CallContext& ctx)
  */
 static naRef f_desktop(const nasal::CallContext& ctx)
 {
-  return validatedPathToNasal(ctx, SGPath::desktop(SGPath(&checkIORules)));
+    return validatedPathToNasal(
+        ctx, SGPath::desktop(SGPath(&SGPath::NasalIORulesChecker)));
 }
 
 /**
-- 
GitLab