# 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: cp.coretag,v 1.5 2007-03-30 23:40:54 pajamian Exp $

UserTag cp Order      from to
UserTag cp addAttr
UserTag cp Version    $Revision: 1.5 $
UserTag cp Routine    <<EOR
require File::Copy;
sub {
	my ($from, $to, $opt) = @_;
#Debug("cp from=$from to=$to umask=$opt->{umask}");
	my $save_mask;
	if($opt->{umask}) {
		$opt->{umask} = oct($opt->{umask});
		$save_mask = umask($opt->{umask});
	}
	my $status = File::Copy::copy($from, $to);

	if ($opt->{preserve_times}) {
		my ($atime, $mtime);

		($atime, $mtime) = (stat $from)[8,9];

		if ($atime) {
			$status = utime($atime, $mtime, $from);
		}
		else {
			$status = 0;
		}
	}

	umask($save_mask) if defined $save_mask;
	return '' if $opt->{hide};
	return $status;
}
EOR
