/* --------------------------------------------------------------- */ /* zerofile -- mark file for merge/deletion. */ /* --------------------------------------------------------------- */ /* */ /* Copyright (c) Mike Cowlishaw, 1985-2013. All rights reserved. */ /* Parts Copyright (c) IBM, 1985-2010. */ /* */ /* Permission to use, copy, modify, and distribute this software */ /* for any non-commercial purpose without fee is hereby granted, */ /* provided that the above copyright notice and this permission */ /* notice appear in all copies, and that notice and the date of */ /* any modifications be added to the software. */ /* */ /* This software is provided "as is". No warranties, whether */ /* express, implied, or statutory, including, but not limited to, */ /* implied warranties of merchantability and fitness for a */ /* particular purpose apply to this software. The author shall */ /* not, in any circumstances, be liable for special, incidental, */ /* or consequential damages, for any reason whatsoever. */ /* */ /* --------------------------------------------------------------- */ /* */ /* This sets the length of a file to 0 and its archive bit to 0. */ /* This indicates that the file is to be deleted when the */ /* directory it is in is synchronized using mergedirs.rex. */ /* */ /* Arg1 is fully qualified filename (\ delimiters) */ /* returns if called as command: */ /* 0 if OK, non-0 if error */ /* returns if called as function: */ /* '' if OK, error message if error */ /* */ /* Will not zero read-only files unless Arg1 is prefixed with ':'. */ /* Will create file if does not exist. */ /* ----------------------------------------------------------------*/ parse source os how . command=(how='COMMAND') parse arg fn if fn='' then do msg='File specification expected' if \command then return msg say msg return 1 end fn=strip(translate(fn, ' ', '"')) -- FM adds "..." sometimes parse var fn pre +1 rest if pre=':' then do -- forced delete fn=strip(rest) -- [in case of space after :] -- clear all attributes (see below) call sysfiletree fn, 'LIST', 'FL',, '-----' end dt=SysGetFileDateTime(fn, "W") -- remember date & time rc=sysfiledelete(fn) if rc\=0 & rc\=2 then do -- rc=2 = does not exist if rc=32 then reason='in use (shared)' else if rc=5 then reason='read-only, directory, or busy' else reason='rc='rc msg=fn 'could not be zeroed ['reason']' if \command then return msg say msg return rc end /* Recreate, as a mark for deletion. */ /* Make file size zero with archive bit off, so merge will erase it */ /* [Genuine size-0 files will have archive bit on.] */ call charout fn, '', 1 -- make new size-0 file call charout fn if dt\='-1' then do -- was not a new file .. parse var dt date time -- .. so make same date as before call SysSetFileDateTime fn, date, time end -- For synchronizable erase, archive bit must be off; use Sysfiletree -- side-effect, which is vastly faster than using commands (see below) call sysfiletree fn, 'LIST', 'FL',, '-****' -- [not much we can do if fails; leave it as a size-0] if \command then return '' -- OK say fn 'zeroed' return 0 /* Old but very slow way of setting attributes without flashies: -- attrib='attrib -a -s -h "'fn'"' -- Ensures unhidden, too -- address cmd 'start /MIN /WAIT' attrib -- MIN so no cmd window flashies */