The problem is that shell.resolve isn't fit for the job here. shell.resolve turns a relative path into an absolute path. In root, "startup" would be resolved to "startup", but in a directory called "dir", it would become "dir/startup". Because the fs lib accepts absolute paths, it's safe to assume that the given path is in fact absolute already...
Though a simple string comparison won't quite suffice here. If you pass "/startup" (note the slash) to the fs functions, you'd be able to access the file anyway. You'd need a way to normalise the file path in order to compare it properly. Luckily, I've already written such a function once, which you can use however you like:
fs.normalise = function(path)
if path == nil then error("path can't be nil", 2) end
local fullPath = path
if fullPath ~= nil then
local continue = true
if fullPath == "" then fullPath = "/"; continue = false end
if fullPath == "/" or fullPath == "\\" then fullPath = "/"; continue = false end
if continue then
fullPath = fullPath:gsub("\\", "/")
if fullPath:sub(1, 1) ~= "/" then
fullPath = "/" .. fullPath
end
if fullPath:sub(#fullPath, #fullPath) == "/" then
fullPath = fullPath:sub(1, #fullPath - 1)
end
end
end
return fullPath
end
fs.normalize = fs.normalise
It's a bit quirky since I've taken it straight from my OS and adjusted it for a general case in the forum editor... but it should work (or at least be easy to correct). It normalises all file paths to this format: "/a/b/c"
So to block system files from being modified, you would do this (pseudocode):
local filePath = ...
local allowed = true
for _,v in pairs({ "/startup", "/aFile", "/anotherFile" }) do
if fs.normalise(filePath) == v do
allowed = false
break
end
end
if not allowed then
...
else
...
end