Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.radio.backup.backupPrefTable
on backupPrefTable (adrtable, fname) {
<<Changes
<<1/14/03; 2:54:15 PM by JES
<<Use xml generated by table.tableToXml for prefs table file format, instead of Fat Page format.
<<11/29/02; 4:33:45 PM by JES
<<Don't back up the mail-to-weblog secret subject.
<<11/29/02; 3:59:46 PM by JES
<<Compare the table contents with the contents of the file on disk from the last backup run. If they are identical, then don't write the file.
<<11/13/02; 10:00:59 AM by DW
<<Created.
local (adrbackup = @system.temp.radioPrefsBackup);
new (tabletype, adrbackup);
bundle { //create and populate a directory at the top level of the table
local (adrdirectory = @adrbackup^.directory);
new (tabletype, adrdirectory);
adrdirectory^.adrobject = adrtable;
adrdirectory^.whenCreated = date.netstandardstring (timeCreated (adrtable));
adrdirectory^.whenModified = date.netstandardstring (timeModified (adrtable));
adrdirectory^.frontierFolder = frontier.pathstring};
bundle { //copy table into "data" sub-table, deal with passwords
<<What we do with passwords..
<<All scalars whose name contains the word password or are contained within tables whose name contains password are set to the empty string.
adrbackup^.data = adrtable^; //copy the table
on visit (adrtable) {
local (sizetable = sizeof (adrtable^), i);
for i = sizetable downto 1 {
adritem = @adrtable^ [i];
local (flsecret = (string.lower (adritem) contains "password") );
if not flsecret {
flsecret = (string.lower (nameOf (adritem^)) == "secretsubject")};
if flsecret {
if typeof (adritem^) != tabletype {
adritem^ = binary ("")}};
if typeof (adritem^) == tabletype {
visit (adritem)}}};
visit (@adrbackup^.data)};
bundle { //write out the file but only if it changed
local (flwrite = true);
local (f = user.radio.backup.prefs.folder + "prefs" + file.getpathchar () + fname + ".xml");
local (s = table.tableToXml (adrbackup));
<<bundle //old fat page-based file format
<<local (f = user.radio.backup.prefs.folder + "prefs" + file.getpathchar () + fname + ".fttb")
<<local (s = fatPages.buildFileAtts (adrbackup, false))
file.surefilepath (f);
if file.exists (f) {
local (localtable, atts);
local (filetext = file.readWholeFile (f));
if filetext == s {
flwrite = false}};
<<bundle //old table comparison code
<<if fatPages.getPageAtts (@filetext, @atts)
<<if defined (atts.pageData)
<<fatPages.unpackOdbObject (@atts, @localtable, flEdit:false)
<<if table.compareContents (@adrbackup^.data, @localtable.data)
<<flwrite = false
if flwrite {
local (filetype = 'TEXT');
<<bundle //old filetype from fat page file format
<<local (filetype = frontier.getFileType (typeOf (adrbackup^)))
file.writeWholeFile (f, s, filetype, user.html.prefs.textFileCreator, clock.now ())}}}
<<bundle //test code
<<backupPrefTable (@weblogData.prefs, "weblogPrefs")
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.