1. atheros
  2. love-mount

Commits

atheros  committed a69d762

Added support for wildcards in automounting archives filenames
Added 2 tests to confirm it works

  • Participants
  • Parent commits 81edad2
  • Branches default

Comments (0)

Files changed (14)

File src/scripts/boot.lua

View file
  • Ignore whitespace
 
 		-- automount archive (before restricting paths!)
 		if love.filesystem.mount and type(c.archives.automount) == 'table' then
-			-- mount archives
+			-- get archives to mount automagically
+			local archives = {}
+			local mountpoint, archive_files, archive_path, archive_paths
 			for k, v in pairs(c.archives.automount) do
 				if type(k) == "string" then
 					-- k=archive, v=mountpoint
 					-- mount archive on given mountpoint
-					love.filesystem.mount(k, v)
+					archive_path = k
+					mountpoint = v
 				else
 					-- k=index (not used), v=archive
 					-- mount archive on /
-					love.filesystem.mount(v)
+					archive_path = v
+					mountpoint = ""
 				end
+				
+				-- split dir from filename (possible a pattern)
+				if string.find(archive_path, "*", 1, true)  ~= nil or string.find(archive_path, "?", 1, true)  ~= nil then
+					local dirname = love.filesystem.dirname(archive_path)
+					local pattern = love.filesystem.basename(archive_path)
+					archive_paths = {}
+					
+					-- expand wildcard to files
+					for i, file in ipairs(love.filesystem.find(dirname, pattern)) do
+						table.insert(archive_paths, dirname .. "/" .. file)
+					end
+				else
+					archive_paths = { archive_path }
+				end
+				
+				-- add archives
+				for i, arch in ipairs(archive_paths) do
+					table.insert(archives, {arch, mountpoint})
+				end
+			end
+			
+			-- mount archives
+			for i, mountopt in ipairs(archives) do
+				love.filesystem.mount(mountopt[1], mountopt[2])
 			end
 		end
 		
 		if love.filesystem.mount then
 			-- now when automounts are done, restrict access to love.filesystem.mount
-			print("Restricting archives!")
 			love.filesystem.restrictArchivePaths(c.archives.allowedpaths)
 		end
 		

File src/scripts/boot.lua.h

View file
  • Ignore whitespace
 	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, 0x2d, 0x2d, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 
-	0x65, 0x73, 0x0a,
+	0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 
+	0x20, 0x74, 0x6f, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x67, 0x69, 
+	0x63, 0x61, 0x6c, 0x6c, 0x79, 0x0a,
+	0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x20, 
+	0x3d, 0x20, 0x7b, 0x7d, 0x0a,
+	0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 
+	0x74, 0x2c, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2c, 0x20, 
+	0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x2c, 0x20, 0x61, 0x72, 0x63, 0x68, 
+	0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x73, 0x0a,
 	0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x20, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69, 
 	0x72, 0x73, 0x28, 0x63, 0x2e, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 
 	0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x29, 0x20, 0x64, 0x6f, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x72, 0x63, 0x68, 
 	0x69, 0x76, 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 
 	0x70, 0x6f, 0x69, 0x6e, 0x74, 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, 0x6b, 0x2c, 0x20, 0x76, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x20, 
+	0x3d, 0x20, 0x6b, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x3d, 0x20, 
+	0x76, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6b, 0x3d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x20, 0x28, 0x6e, 
 	0x6f, 0x74, 0x20, 0x75, 0x73, 0x65, 0x64, 0x29, 0x2c, 0x20, 0x76, 0x3d, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 
 	0x65, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x72, 0x63, 0x68, 
 	0x69, 0x76, 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x2f, 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, 0x76, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x20, 
+	0x3d, 0x20, 0x76, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x20, 0x3d, 0x20, 
+	0x22, 0x22, 0x0a,
 	0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x20, 0x64, 0x69, 0x72, 0x20, 0x66, 
+	0x72, 0x6f, 0x6d, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x28, 0x70, 0x6f, 0x73, 0x73, 
+	0x69, 0x62, 0x6c, 0x65, 0x20, 0x61, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 
+	0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x2c, 0x20, 0x22, 0x2a, 0x22, 
+	0x2c, 0x20, 0x31, 0x2c, 0x20, 0x74, 0x72, 0x75, 0x65, 0x29, 0x20, 0x20, 0x7e, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 
+	0x20, 0x6f, 0x72, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x61, 0x72, 
+	0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x2c, 0x20, 0x22, 0x3f, 0x22, 0x2c, 0x20, 0x31, 
+	0x2c, 0x20, 0x74, 0x72, 0x75, 0x65, 0x29, 0x20, 0x20, 0x7e, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 
+	0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x64, 0x69, 0x72, 0x6e, 0x61, 0x6d, 0x65, 
+	0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 
+	0x2e, 0x64, 0x69, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 
+	0x61, 0x74, 0x68, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 
+	0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 
+	0x2e, 0x62, 0x61, 0x73, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 
+	0x70, 0x61, 0x74, 0x68, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x73, 
+	0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x77, 0x69, 0x6c, 
+	0x64, 0x63, 0x61, 0x72, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, 
+	0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 
+	0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x66, 0x69, 0x6e, 0x64, 0x28, 0x64, 0x69, 0x72, 0x6e, 0x61, 0x6d, 
+	0x65, 0x2c, 0x20, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x29, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 
+	0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x73, 0x2c, 0x20, 0x64, 0x69, 
+	0x72, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2f, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x66, 0x69, 
+	0x6c, 0x65, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x73, 
+	0x20, 0x3d, 0x20, 0x7b, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x20, 
+	0x7d, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x64, 0x64, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 
+	0x73, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x20, 0x61, 0x72, 0x63, 0x68, 0x20, 0x69, 0x6e, 
+	0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 
+	0x74, 0x68, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x28, 
+	0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x2c, 0x20, 0x7b, 0x61, 0x72, 0x63, 0x68, 0x2c, 0x20, 0x6d, 
+	0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x7d, 0x29, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x09, 0x0a,
+	0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 
+	0x65, 0x73, 0x0a,
+	0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x6f, 0x70, 0x74, 
+	0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 
+	0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	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, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x6f, 0x70, 0x74, 0x5b, 0x31, 
+	0x5d, 0x2c, 0x20, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x6f, 0x70, 0x74, 0x5b, 0x32, 0x5d, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x09, 0x0a,
 	0x72, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x74, 0x6f, 
 	0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x6d, 
 	0x6f, 0x75, 0x6e, 0x74, 0x0a,
-	0x09, 0x09, 0x09, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x28, 0x22, 0x52, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 
-	0x69, 0x6e, 0x67, 0x20, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x73, 0x21, 0x22, 0x29, 0x0a,
 	0x09, 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, 0x73, 0x2e, 0x61, 0x6c, 0x6c, 

File tests/basic-automount-multi/conf.lua

View file
  • Ignore whitespace
+function love.conf(t)
+	-- allow mounting archives from anywhere
+	t.archives.allowedpaths = {""}
+	t.archives.automount = {"test1.zip", "test2.zip", ["test3.zip"] = "/addons" }
+end

File tests/basic-automount-multi/main.lua

View file
  • Ignore whitespace
+
+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"))
+		print("The message from mounted archive: "..love.filesystem.read("TextFile2.txt"))
+		print("The message from mounted archive: "..love.filesystem.read("addons/TextFile.txt"))
+	end
+
+	print("Now I'm going to save some kittens by proving you can't umount an automounted archive!")
+	local code, msg = pcall(love.filesystem.umount, "test.zip")
+	if code == false then
+		print("Confirmed!")
+	else
+		print("Umount succeeded when it should have failed! Hopefully it didn't kill any kittens...")
+	end
+
+	return exit()
+end

File tests/basic-automount-multi/test.sh

View file
  • Ignore whitespace
+#!/bin/sh
+../../src/love .

File tests/basic-automount-multi/test1.zip

  • Ignore whitespace
Binary file added.

File tests/basic-automount-multi/test2.zip

  • Ignore whitespace
Binary file added.

File tests/basic-automount-multi/test3.zip

  • Ignore whitespace
Binary file added.

File tests/basic-automount-wildcard/conf.lua

View file
  • Ignore whitespace
+function love.conf(t)
+	-- allow mounting archives from anywhere
+	t.archives.allowedpaths = {""}
+	t.archives.automount = {["*.zip"] = "/addons" }
+end

File tests/basic-automount-wildcard/main.lua

View file
  • Ignore whitespace
+
+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("/addons")) do
+		print("found file \"" .. file .. "\"")
+	end
+	
+	exit();
+end

File tests/basic-automount-wildcard/test.sh

View file
  • Ignore whitespace
+#!/bin/sh
+../../src/love .

File tests/basic-automount-wildcard/test1.zip

  • Ignore whitespace
Binary file added.

File tests/basic-automount-wildcard/test2.zip

  • Ignore whitespace
Binary file added.

File tests/basic-automount-wildcard/test3.zip

  • Ignore whitespace
Binary file added.