source: trunk/base/src/port/portmirror.tcl @ 34393

Last change on this file since 34393 was 34393, checked in by raimue@…, 13 years ago

port/port*.tcl
Remove backslash from modeline because vim complains about it

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#!/bin/sh
2# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
3# Run the Tcl interpreter \
4exec @TCLSH@ "$0" "$@"
5# portmirror.tcl
6# $Id: portmirror.tcl 34393 2008-02-23 01:35:31Z raimue@macports.org $
7#
8# Copyright (c) 2002-2007 The MacPorts Project.
9# All rights reserved.
10#
11# Updates the distfiles to current distfiles by deleting old stuff.
12# Uses the database.
13
14catch {source \
15    [file join "@TCL_PACKAGE_DIR@" macports1.0 macports_fastload.tcl]}
16package require macports
17package require Pextlib
18
19# Globals
20global distfiles_filemap
21array set ui_options        [list]
22array set global_options    [list]
23array set global_variations [list]
24
25# Pass global options into mportinit
26mportinit ui_options global_options global_variations
27
28
29# Iterate on dist files.
30#
31# func:     function to call on every dist file (it is passed
32#           the path as its parameter)
33# root:     the directory with all the dist files (full path).
34proc iterate_distfiles_r {func root} {
35    foreach item [readdir $root] {
36        set pathToItem [file join $root $item]
37        if {[file isdirectory $pathToItem]} {
38            iterate_distfiles_r $func $pathToItem
39        } else {
40            $func $pathToItem
41        }
42    }
43}
44
45# Iterate on dist files.
46#
47# func:     function to call on every dist file (it is passed
48#           the path as its parameter)
49proc iterate_distfiles {func} {
50    global macports::portdbpath
51    iterate_distfiles_r $func [file join ${macports::portdbpath} distfiles]
52}
53
54# Check if the file is in the map and delete it otherwise.
55proc iterate_walker {path} {
56    global distfiles_filemap
57    if {![filemap exists distfiles_filemap $path]} {
58        puts "deleting $path"
59        file delete -force $path
60    }
61}
62
63# Open the database
64proc open_database args {
65    global macports::portdbpath distfiles_filemap
66    set path [file join ${macports::portdbpath} distfiles_mirror.db]
67    if {[file exists $path]} {
68        filemap open distfiles_filemap $path readonly
69    } else {
70        return -code error "The database doesn't exist at <$path>"
71    }
72}
73
74# Close the database
75proc close_database args {
76    global distfiles_filemap
77    filemap close distfiles_filemap
78}
79
80# Standard procedures
81proc print_usage args {
82    global argv0
83    puts "Usage: $argv0"
84}
85
86if {[expr $argc > 0]} {
87    print_usage
88    exit 1
89}
90
91# Open the database.
92open_database
93
94# Iterate on the files, deleting them.
95iterate_distfiles iterate_walker
96
97# Close the database
98close_database
Note: See TracBrowser for help on using the repository browser.