Name

unlink_file — safely delete a file within catalog root directory

ATTRIBUTES

Attribute Pos. Req. Default Description
name Yes Yes   File name to delete
prefix Yes   tmp/ Prefix that the filename must match (a safety measure)
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

The tag safely deletes a file from the catalog root directory (CATROOT).

The beginning of the filename must match the prefix= option for the deletion to succeed.

The filename can not start with a / nor ../.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: create and delete file "tmp/testfile"

[tmp]

[write-relative-file tmp/testfile]
  Hello, World!
[/write-relative-file]

[unlink-file tmp/testfile]

[/tmp]

The [tmp] tag is only used to hide output values from the two contained tags.


Example: delete file "logs/tmplog"

[tmp] [unlink-file name="logs/tmplog" prefix="logs/"] [/tmp]


NOTES

AVAILABILITY

unlink_file is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/UI_Tag/unlink_file.coretag
Lines: 23


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: unlink_file.coretag,v 1.5 2007-03-30 23:40:54 pajamian Exp $

UserTag unlink_file Order      name prefix
UserTag unlink_file PosNumber  2
UserTag unlink_file Version    $Revision: 1.5 $
UserTag unlink_file Routine    <<EOR
sub {
my ($file, $prefix) = @_;
#::logDebug("got to unlink: file=$file prefix=$prefix");
$prefix = 'tmp/' unless $prefix;
return if Vend::File::absolute_or_relative($file);
return unless $file =~ /^$prefix/;
#::logDebug("got to unlink: $file qualifies");
unlink $file;
}
EOR

AUTHORS

Interchange Development Group

SEE ALSO

write-relative-file(7ic)

DocBook! Interchange!