Commits

textmode committed 22c538e

added automounting + testcase, moved config fields to t.archives.*

Comments (0)

Files changed (9)

src/scripts/boot.lua

 			font = true,
 			thread = true,
 		},
-		archivepaths = {},
+		archives = {
+			allowedpaths = {""},
+			automount = {},
+		},
 		console = false, -- Only relevant for windows.
 		identity = false,
 		release = false,
 	if love.filesystem then
 		love.filesystem.setRelease(c.release and is_fused_game)
 		if c.identity then love.filesystem.setIdentity(c.identity) end
-		love.filesystem.restrictArchivePaths(c.archivepaths)
+
+		-- archive mounting changes
+		love.filesystem.restrictArchivePaths(c.archives.allowedpaths)
+		if love.filesystem.mount and type(c.archives.automount) == 'table' then
+			for i=1,#c.archives.automount do
+				if type(c.archives.automount[i]) == 'string' then
+					love.filesystem.mount(c.archives.automount[i])
+				end
+			end
+		end
+
 		if love.filesystem.exists("main.lua") then require("main") end
+
 	end
 
 	if no_game_code then

src/scripts/boot.lua.h

 	0x09, 0x09, 0x09, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a,
 	0x09, 0x09, 0x09, 0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a,
 	0x09, 0x09, 0x7d, 0x2c, 0x0a,
-	0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x70, 0x61, 0x74, 0x68, 0x73, 0x20, 0x3d, 0x20, 0x7b, 
-	0x7d, 0x2c, 0x0a,
+	0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a,
+	0x09, 0x09, 0x09, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x70, 0x61, 0x74, 0x68, 0x73, 0x20, 0x3d, 0x20, 
+	0x7b, 0x22, 0x22, 0x7d, 0x2c, 0x0a,
+	0x09, 0x09, 0x09, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x2c, 0x0a,
+	0x09, 0x09, 0x7d, 0x2c, 0x0a,
 	0x09, 0x09, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 
 	0x20, 0x2d, 0x2d, 0x20, 0x4f, 0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 
 	0x66, 0x6f, 0x72, 0x20, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x2e, 0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x74, 0x68, 
 	0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 
 	0x2e, 0x73, 0x65, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x28, 0x63, 0x2e, 0x69, 0x64, 0x65, 
-	0x6e, 0x74, 0x69, 0x74, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x6e, 0x74, 0x69, 0x74, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,0x0a,
+	0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 
+	0x69, 0x6e, 0x67, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 
 	0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x41, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x50, 0x61, 0x74, 
-	0x68, 0x73, 0x28, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x70, 0x61, 0x74, 0x68, 0x73, 0x29, 0x0a,
+	0x68, 0x73, 0x28, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x61, 0x6c, 0x6c, 0x6f, 
+	0x77, 0x65, 0x64, 0x70, 0x61, 0x74, 0x68, 0x73, 0x29, 0x0a,
+	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 
+	0x65, 0x6d, 0x2e, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 
+	0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x6f, 0x75, 
+	0x6e, 0x74, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x27, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x27, 0x20, 0x74, 0x68, 0x65, 
+	0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x23, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 
+	0x69, 0x76, 0x65, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x64, 0x6f, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 
+	0x69, 0x76, 0x65, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5b, 0x69, 0x5d, 0x29, 
+	0x20, 0x3d, 0x3d, 0x20, 0x27, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x27, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 
+	0x65, 0x6d, 0x2e, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x28, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 
+	0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5b, 0x69, 0x5d, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 
 	0x65, 0x6d, 0x2e, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x28, 0x22, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6c, 0x75, 
 	0x61, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x22, 
-	0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,0x0a,
 	0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x5f, 0x67, 0x61, 0x6d, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 
 	0x68, 0x65, 0x6e, 0x0a,

tests/basic-automount/conf.lua

+function love.conf(t)
+	-- allow mounting archives from anywhere
+	t.archives.allowedpaths = {""}
+	t.archives.automount = {"test.zip"}
+end

tests/basic-automount/main.lua

+
+function exit()
+	love.event.push("q")
+end
+
+function love.load()
+	local found = false
+
+	-- automount should have mounted 'test.zip' for us,
+	-- so lets go through all files
+	print("Top level files:")
+	for k, file in ipairs(love.filesystem.enumerate("/")) do
+		print("found file \"" .. file .. "\"")
+		if file == "TextFile.txt" then
+			found = true
+		end
+	end
+	
+	if not found then
+		print("Mounting of archive somehow failed!")
+		return exit()
+	else
+		print("The message from mounted archive: "..love.filesystem.read("TextFile.txt"))
+	end
+
+	print("Now I'm going to save some kittens by umounting that archive!")
+	love.filesystem.umount("test.zip")
+		
+	-- go through all files
+	print("Now let's confirm archive is no longer available")
+	found = false
+	print("Top level files:")
+	for k, file in ipairs(love.filesystem.enumerate("/")) do
+		print("found file \"" .. file .. "\"")
+		if file == "TextFile.txt" then
+			found = true
+		end
+	end
+	
+	if not found then
+		print("Archive successfully umounted!")
+	else
+		print("Umounting of archive somehow failed! Message reads: "..love.filesystem.read("TextFile.txt"))
+	end
+	
+	return exit()
+end

tests/basic-automount/test.sh

+#!/bin/sh
+../../src/love .

tests/basic-automount/test.zip

Binary file added.

tests/basic-check-restrictions/conf.lua

 function love.conf(t)
 	-- allow mounting archives from anywhere
-	t.archivepaths = {"addons"}
-end
+	t.archives.allowedpaths = {"addons"}
+end

tests/basic-mount/conf.lua

 function love.conf(t)
 	-- allow mounting archives from anywhere
-	t.archivepaths = {""}
-end
+	t.archives.allowedpaths = {""}
+end

tests/basic-overloading/conf.lua

 function love.conf(t)
 	-- allow mounting archives from anywhere
-	t.archivepaths = {""}
-end
+	t.archives.allowedpaths = {""}
+end