unlink_file — safely delete a file within catalog root directory
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? |
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 ../
.
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.
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