Monday, November 08, 2010 at 12:04 AM.

system.verbs.builtins.mainResponder.background.everyNight

<<Run mainResponder's every night scripts.
	<<Changes:
		<<Thu, 25 Feb 1999 02:16:25 GMT by AR
			<<Added the backupmodifiedfile sub-routine and some support code.
				<<This sub-routine only copies the file, if no current backup copy exists.
				<<For now, it's only called to back up the files in the www subfolder.
		<<Thu, 25 Feb 1999 16:42:09 GMT by AR
			<<Files that don't need to be backed up are no longer added to filetable.
		<<Tue, Mar 9, 1999 at 4:07:09 PM by PBS
			<<Use Frontier.getSubFolder rather than mainResponder.getFolder.
		<<Wed, 28 Apr 1999 20:50:13 GMT by AR
			<<Modified backupmodifiedfile subroutine to better handle files that are currently open but haven't been modified yet, using window.ismodified
		<<8/13/99; 7:54:12 PM by DW
			<<call mainResponder.discuss.everyNight if pref is true
		<<05/15/00; 9:25:28 PM by PBS
			<<Don't do root updates at this time. The problem is that they were all bunched up together on the hour, and people's roots were not getting updated due to the competition.

if config.mainResponder.prefs.flBackupNightly {
	local (folder = config.mainresponder.prefs.backupfolder);
	local (backupname = mainResponder.getDateFileName (clock.now ()));
	local (subfolder = folder + backupname + file.getpathchar ());
	local (filetable); new (tabletype, @filetable);
	local (folderlist = {}); //list of names of previous backup folders
	file.surefilepath (subfolder);
	window.about ();
	
	on backupfile (f, basefolder) {
		local (relpath = string.delete (f, 1, sizeof (basefolder)));
		local (destfile = subfolder + relpath);
		file.surefilepath (destfile);
		msg ("mainResponder.background.everyNight: backing up " + file.filefrompath (destfile));
		try {
			file.copy (f, destfile);
			filetable.[destfile] = file.size (destfile)}
		else {
			filetable.[destfile] = tryError}};
	on backupmodifiedfile (f, basefolder) { //Wed, 28 Apr 1999 20:50:13 GMT by AR
		local (i, fBackItUp = true, moddate = file.modified (f));
		local (relpath = string.delete (f, 1, sizeof (basefolder)));
		local (destfile = subfolder + relpath);
		if window.isopen (f) and window.ismodified (f) { // save file so it will be backed up
			filemenu.save (f)};
		for i = sizeOf (folderlist) downto 1 {
			local (path = folder + folderlist[i] + relpath);
			if file.exists (path) && (file.modified (path) == moddate) {
				fBackItUp = false;
				break}};
		if fBackItUp {
			file.surefilepath (destfile);
			msg ("mainResponder.background.everyNight: backing up " + file.filefrompath (destfile));
			try {
				file.copy (f, destfile);
				filetable.[destfile] = file.size (destfile)}
			else {
				filetable.[destfile] = tryError}}};
	bundle { //build folderlist
		msg ("mainResponder.background.everyNight: preparing backups");
		on addFolder (path) {
			if file.isFolder (path) {
				folderlist = folderlist + file.fileFromPath (path)}};
		file.visitFolder (folder, 1, @addFolder);
		folderlist = folderlist - (backupname + file.getpathchar ()); //drop current backup folder
		if sizeOf (folderlist) > 0 {
			local (tempoutline); new (outlineType, @tempoutline);
			op.listToOutline (folderlist, @tempoutline);
			local (oldtarget = target.set (@tempoutline));
			op.firstSummit ();
			op.deleteLine ();
			op.sort (); //sort folders in ascending temporal order
			target.set (oldtarget);
			folderlist = op.outlineToList (@tempoutline, flWholeOutline:true)}};
	bundle { //back up Frontier.root
		local (frontierroot = file.folderfrompath (Frontier.getProgramPath ()) + "Frontier.root");
		filemenu.save (frontierroot);
		backupfile (frontierroot, file.folderfrompath (frontierroot))};
	bundle { //back up the whole apps folder
		local (appsfolder = Frontier.getSubFolder ("/apps/"), f); //PBS 3/9/99
		fileloop (f in appsfolder, infinity) {
			if window.isopen (f) {
				filemenu.save (f)};
			backupfile (f, file.folderfrompath (appsfolder))}};
	bundle { //back up specific files in the ops folder
		local (opsfolder = Frontier.getSubFolder ("/ops/")); //PBS 3/9/99
		try {backupfile (opsfolder + "members.root", file.folderfrompath (opsfolder))};
		try {backupfile (opsfolder + "discuss.root", file.folderfrompath (opsfolder))};
		try {backupfile (opsfolder + "Index.root", file.folderfrompath (opsfolder))}}; //PBS 1/22/99
	bundle { //back up the whole www folder
		local (wwwfolder = Frontier.getSubFolder ("/www/"), f);
		fileloop (f in wwwfolder, infinity) {
			backupmodifiedfile (f, file.folderfrompath (wwwfolder))}};
	bundle { //add a log entry for this backup
		subtaskinfo.backupFileTable = filetable};
	bundle { //call the callback scripts
		local (params);
		new (tabletype, @params);
		params.filetable = filetable; //the callback script just refers to "filetable"
		params.backupfolder = subfolder; //the callback script just refers to "backupfolder"
		mainResponder.callbackLoop (@config.mainresponder.callbacks.nightlyBackup, @params)}};
if config.mainresponder.prefs.flDiscussStatsNightly { //8/13/99; 7:54:04 PM by DW
	mainResponder.discuss.everyNight ()}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.