Does anyone know how to go about setting up a LUA file to copy files from Directory A to Directory B?
Reason I want this, is so I can automate the process of transfering the Cache directory from GarrysMod folder, to the FastDL directory - instead of having to manually do it on each new addon being added.
I do see there is a module/binary called gm_rawio or something like that.
Can someone suggest the lua script that would do what I need?
It would need to execute after the lua cache has been generated, but before players start connecting.
You are in luck good sir, for I have found a need for this lately and made this myself a few days ago.
Extract [url=http://dl.dropbox.com/u/1660572/gmod_dlls/gmsv_copycache.zip]this[/url] and put it in lua/includes/modules - you can see the source code for the module [url=http://dl.dropbox.com/u/1660572/gmod_dlls/gmsv_copycache.cpp]here[/url].
Then, save this script in lua/autorun/server:
[code]require( "copycache" )
local function NetworkCache( )
local ok, err, lst, k
lst = file.Find( "cache/*.dua", true )
table.sort( lst, function( a, b ) return file.Time( "../cache/" .. a ) > file.Time( "../cache/" .. b ) end )
k = lst[ 1 ]
ok, err = CopyCacheFile( ( util.RelativePathToFull( "cache/" .. k ) ), "\\\\SQL-SERVER\\garrysmod/cache/" .. k )
if not ok then
error( "There was an error copying the cache file\n" .. tostring( err ) .. "\n" )
end
end
local function Initialize( )
timer.Simple( 0, NetworkCache )
end
hook.Add( "Initialize", "CopyCache:Initialize", Initialize )[/code]
The script automatically selects the newest cache file for you.
Just replace this
[code]"\\\\SQL-SERVER\\garrysmod/cache/"[/code]
with the absolute path to your fastdl folder. My fastdl is on another computer that I have a network share with, but if it is on the same computer would just put X:/path/to/cache. Make sure you have write access.
Hi Kogitsune,
Thanks for the reply.
I had a go at making a simple wee app to handle it for me.
It basically runs in the background of the server,
Gets the MD5 of the Cache files in the Server folder, and compares it to the md5 of the cache files in the FastDL folder.
If they mismatch, or a file is missing etc.
It triggers a Deletion of the Cache folder on the FastDL, then copies the contents of the Server version to the FastDL again.
Its pretty well optimized, does this check every 20 seconds, so it essentially updates and checks the cache in real time.
I've just got to figure out where the memory leak is happening at....
The app keeps gaining 100-300kb of memory usage every so often, Im just worried that it would seize up if it was left running for multiple days.
Workaround =
When Memory usage >= x
Automatically make the App Restart itself.
The cache file is only created once, after the gamemode Initializes but before the first frame. If you upload the cache here, unthreaded, the server will copy the file to your fastdl location before the first player can join even over lan. I know this because I am on the same lan as the server. I don't think you can possible make it more efficient than that without just creating a junction between the fastdl cache folder and your server's cache folder if they are on the same hard drive.
You shouldn't poll the cash that often - either use a trigger based method like FileSystemWatcher or a module that does the copy as soon as the game creates the cache.
Although I don't know the language you are using, but your memory leak could be not freeing file handles / closing files if the language demands it.
Its C# its wrote in,
I've made sure to set all objects to null when done with them, and to reuse objects without creating new ones etc.
It still seems to gain a few hundred kb within a few minutes.
Anyway, I can live with it the way it is.
It doesnt copy the cache, if the cache doesnt need copied.
Thats what the MD5 check is for, to ensure that the FastDL ones match up to the Server version, if there are any differences, then it deletes the FastDL Cache folder completed, then copies the whole thing over again.
Sorry, you need to Log In to post a reply to this thread.