<commit_before># et:ts=4
# portinstall.tcl
# $Id$
#
# Copyright (c) 2002 - 2003 Apple Computer, Inc.
# Copyright (c) 2004 <NAME> <<EMAIL>>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

package provide portinstall 1.0
package require portutil 1.0

set org.macports.install [target_new org.macports.install portinstall::install_main]
target_provides ${org.macports.install} install
target_runtype ${org.macports.install} always
if {[option portarchivemode] == "yes"} {
    target_requires ${org.macports.install} main unarchive fetch extract checksum patch configure build destroot archive
} else {
    target_requires ${org.macports.install} main fetch extract checksum patch configure build destroot
}
target_prerun ${org.macports.install} portinstall::install_start

namespace eval portinstall {
}

# define options
options install.asroot

# Set defaults
default install.asroot no

set_ui_prefix

proc portinstall::install_start {args} {
    global UI_PREFIX name version revision portvariants
    global prefix
    ui_msg "$UI_PREFIX [format [msgcat::mc "Installing %s @%s_%s%s"] $name $version $revision $portvariants]"
    
    # start gsoc08-privileges
    if { ![file writable $prefix] } {
        # if install location is not writable, need root privileges to install
        elevateToRoot "install"
    }
    # end gsoc08-privileges
}

proc portinstall::install_element {src_element dst_element} {
    # don't recursively copy directories
    if {[file isdirectory $src_element] && [file type $src_element] != "link"} {
        file mkdir $dst_element
    } else {
        file copy -force $src_element $dst_element
    }
    
    # if the file is a symlink, do not try to set file attributes
    if {[file type $src_element] != "link"} {
        # tclsh on 10.6 doesn't like the combination of 0444 perm and
        # '-creator {}' (which is returned from 'file attributes <file>'; so
        # instead just set the attributes which are needed
        set wantedattrs {owner group permissions}
        set file_attr_cmd {file attributes $dst_element}
        foreach oneattr $wantedattrs {
            set file_attr_cmd "$file_attr_cmd -$oneattr \[file attributes \$src_element -$oneattr\]"
        }
        eval $file_attr_cmd
        # set mtime on installed element
        file mtime $dst_element [file mtime $src_element]
    }
}

proc portinstall::directory_dig {rootdir workdir imagedir {cwd ""} {prepend 1}} {
    global installPlist
    set pwd [pwd]
    if {[catch {_cd $workdir} err]} {
        puts $err
        return
    }

    set root [file join [file separator] $imagedir]
    foreach name [readdir .] {
        set element [file join $cwd $name]

        set dst_element [file join $root $element]
        set src_element [file join $rootdir $element]
        # overwrites files but not directories
        if {![file exists $dst_element] || ![file isdirectory $dst_element]} {
            if {[file type $src_element] == "link"} {
                ui_debug "installing link: $dst_element"
            } elseif {[file isdirectory $src_element]} {
                ui_debug "installing directory: $dst_element"
            } else {
                ui_debug "installing file: $dst_element"
            }
            install_element $src_element $dst_element
            # only track files/links for registry, not directories
            if {[file type $dst_element] != "directory"} {
                if {$prepend} {
                    lappend installPlist $dst_element
                } else {
                    lappend installPlist [file join [file separator] $element]
                }
            }
        }
        if {[file isdirectory $name] && [file type $name] != "link"} {
            directory_dig $rootdir $name $imagedir [file join $cwd $name]
        }
    }
    _cd $pwd
}

proc portinstall::install_main {args} {
    global name version portpath categories description long_description \
    homepage depends_run installPlist package-install uninstall workdir \
    worksrcdir UI_PREFIX destroot revision maintainers ports_force \
    portvariants targets depends_lib PortInfo epoch license registry.installtype registry.path

    if {[string equal ${registry.format} "receipt_sqlite"]} {<commit_msg>missing global in portinstall (https://trac.macports.org/ticket/23578)<commit_after># et:ts=4
# portinstall.tcl
# $Id$
#
# Copyright (c) 2002 - 2003 Apple Computer, Inc.
# Copyright (c) 2004 <NAME> <<EMAIL>>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

package provide portinstall 1.0
package require portutil 1.0

set org.macports.install [target_new org.macports.install portinstall::install_main]
target_provides ${org.macports.install} install
target_runtype ${org.macports.install} always
if {[option portarchivemode] == "yes"} {
    target_requires ${org.macports.install} main unarchive fetch extract checksum patch configure build destroot archive
} else {
    target_requires ${org.macports.install} main fetch extract checksum patch configure build destroot
}
target_prerun ${org.macports.install} portinstall::install_start

namespace eval portinstall {
}

# define options
options install.asroot

# Set defaults
default install.asroot no

set_ui_prefix

proc portinstall::install_start {args} {
    global UI_PREFIX name version revision portvariants
    global prefix
    ui_msg "$UI_PREFIX [format [msgcat::mc "Installing %s @%s_%s%s"] $name $version $revision $portvariants]"
    
    # start gsoc08-privileges
    if { ![file writable $prefix] } {
        # if install location is not writable, need root privileges to install
        elevateToRoot "install"
    }
    # end gsoc08-privileges
}

proc portinstall::install_element {src_element dst_element} {
    # don't recursively copy directories
    if {[file isdirectory $src_element] && [file type $src_element] != "link"} {
        file mkdir $dst_element
    } else {
        file copy -force $src_element $dst_element
    }
    
    # if the file is a symlink, do not try to set file attributes
    if {[file type $src_element] != "link"} {
        # tclsh on 10.6 doesn't like the combination of 0444 perm and
        # '-creator {}' (which is returned from 'file attributes <file>'; so
        # instead just set the attributes which are needed
        set wantedattrs {owner group permissions}
        set file_attr_cmd {file attributes $dst_element}
        foreach oneattr $wantedattrs {
            set file_attr_cmd "$file_attr_cmd -$oneattr \[file attributes \$src_element -$oneattr\]"
        }
        eval $file_attr_cmd
        # set mtime on installed element
        file mtime $dst_element [file mtime $src_element]
    }
}

proc portinstall::directory_dig {rootdir workdir imagedir {cwd ""} {prepend 1}} {
    global installPlist
    set pwd [pwd]
    if {[catch {_cd $workdir} err]} {
        puts $err
        return
    }

    set root [file join [file separator] $imagedir]
    foreach name [readdir .] {
        set element [file join $cwd $name]

        set dst_element [file join $root $element]
        set src_element [file join $rootdir $element]
        # overwrites files but not directories
        if {![file exists $dst_element] || ![file isdirectory $dst_element]} {
            if {[file type $src_element] == "link"} {
                ui_debug "installing link: $dst_element"
            } elseif {[file isdirectory $src_element]} {
                ui_debug "installing directory: $dst_element"
            } else {
                ui_debug "installing file: $dst_element"
            }
            install_element $src_element $dst_element
            # only track files/links for registry, not directories
            if {[file type $dst_element] != "directory"} {
                if {$prepend} {
                    lappend installPlist $dst_element
                } else {
                    lappend installPlist [file join [file separator] $element]
                }
            }
        }
        if {[file isdirectory $name] && [file type $name] != "link"} {
            directory_dig $rootdir $name $imagedir [file join $cwd $name]
        }
    }
    _cd $pwd
}

proc portinstall::install_main {args} {
    global name version portpath categories description long_description \
    homepage depends_run installPlist package-install uninstall workdir \
    worksrcdir UI_PREFIX destroot revision maintainers ports_force \
    portvariants targets depends_lib PortInfo epoch license \
    registry.installtype registry.path registry.format

    if {[string equal ${registry.format} "receipt_sqlite"]} {
{'fraction_non_alphanumeric': 0.07834101382488479, 'fraction_numerical': 0.00599947830623424, 'mean_word_length': 3.1749546279491834, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5689732', 'n_tokens_mistral': 3275, 'n_tokens_neox': 3071, 'n_words': 1223}