You've already forked macports-base
mirror of
https://github.com/macports/macports-base.git
synced 2026-07-12 18:18:43 -07:00
port: add -W to touch command
Instead of having to use system(), use touch -W dir file See https://trac.macports.org/ticket/53730
This commit is contained in:
committed by
Rainer Müller
parent
101725c1b7
commit
a90c4b29ac
@@ -1055,6 +1055,8 @@ proc delete {args} {
|
||||
# touch
|
||||
# mimics the BSD touch command
|
||||
proc touch {args} {
|
||||
global worksrcpath
|
||||
set dir ${worksrcpath}
|
||||
while {[string match "-*" [lindex $args 0]]} {
|
||||
set arg [string range [lindex $args 0] 1 end]
|
||||
set args [lrange $args 1 end]
|
||||
@@ -1072,6 +1074,10 @@ proc touch {args} {
|
||||
set options($arg) $narg
|
||||
set options(rt) $arg ;# later option overrides earlier
|
||||
}
|
||||
W {
|
||||
set dir [lindex $args 0]
|
||||
set args [lrange $args 1 end]
|
||||
}
|
||||
- break
|
||||
default {return -code error "touch: illegal option -- $arg"}
|
||||
}
|
||||
@@ -1123,10 +1129,14 @@ proc touch {args} {
|
||||
# do we have any files to process?
|
||||
if {[llength $args] == 0} {
|
||||
# print usage
|
||||
return -code error {usage: touch [-a] [-c] [-m] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...}
|
||||
return -code error {usage: touch [-a] [-c] [-m] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] [-W dir] file ...}
|
||||
}
|
||||
|
||||
foreach file $args {
|
||||
# if $file is an absolute path already, file join will just
|
||||
# return the absolute path, otherwise it is $dir/$file
|
||||
set file [file join $dir $file]
|
||||
|
||||
if {![file exists $file]} {
|
||||
if {[info exists options(c)]} {
|
||||
continue
|
||||
|
||||
@@ -365,18 +365,53 @@ test delete {
|
||||
test touch {
|
||||
Touch unit test.
|
||||
} -setup {
|
||||
set dir "/tmp"
|
||||
set file "macports-portutil-touch"
|
||||
set file2 "macports-portutil-touch2"
|
||||
set root "/tmp/macports-portutil-touch"
|
||||
set root2 "/tmp/macports-portutil-touch2"
|
||||
file delete -force $root
|
||||
file delete -force $root2
|
||||
} -body {
|
||||
# -c: do not create file
|
||||
touch -c $root
|
||||
if {[file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
|
||||
touch -c -W $dir $file
|
||||
if {[file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
|
||||
touch -W $dir -c $file
|
||||
if {[file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
|
||||
touch $root
|
||||
if {![file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root
|
||||
|
||||
touch -W $dir $root
|
||||
if {![file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root
|
||||
|
||||
touch -W $dir $file
|
||||
if {![file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root
|
||||
|
||||
touch -W $dir $root $root2
|
||||
if {![file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root
|
||||
if {![file exists $root2]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root2
|
||||
|
||||
touch -W $dir $file $file2
|
||||
if {![file exists $root]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root
|
||||
if {![file exists $root2]} { return "FAIL: touch unsuccessful" }
|
||||
file delete -force $root2
|
||||
|
||||
return "Files successfully touched."
|
||||
|
||||
} -cleanup {
|
||||
file delete -force $root
|
||||
file delete -force $root2
|
||||
} -result "Files successfully touched."
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user