Changeset 106

Show
Ignore:
Timestamp:
11/15/06 21:13:28 (2 years ago)
Author:
Gregor
Message:

hcf/path.d: New function: rmRecursive.

sss/main.d: Updated docs for dsss net.

sss/net.d: Added 'fetch' function, made fetch and install clean up after themselves.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/hcf/path.d

    r86 r106  
    170170    } 
    171171} 
     172 
     173/** Remove a file or directory and all of its children */ 
     174void rmRecursive(char[] name) 
     175{ 
     176    if (isdir(name)) { 
     177        foreach (elem; listdir(name)) { 
     178            // don't delete . or .. 
     179            if (elem == "." || 
     180                elem == "..") continue; 
     181            rmRecursive(elem); 
     182        } 
     183         
     184        // remove the directory itself 
     185        rmdir(name); 
     186    } else { 
     187        std.file.remove(name); 
     188    } 
     189} 
  • trunk/sss/main.d

    r86 r106  
    310310    deps:    Install (from the network source) dependencies of the present 
    311311             package 
    312     install: Install a package via the network source` 
     312    install: Install a package via the network source 
     313    fetch:   Fetch but do not compile or install a package` 
    313314            ); 
    314315 
  • trunk/sss/net.d

    r99 r106  
    134134        } 
    135135         
     136        case "fetch": 
    136137        case "install": 
    137138        { 
    138139            // download and install the specified package and its dependencies 
    139140            if (args.length < 2) { 
    140                 writefln("The install command requires a package name as an argument."); 
     141                writefln("No package name specified."); 
    141142                return 1; 
    142143            } 
     
    151152            char[] srcDir = scratchPrefix ~ std.path.sep ~ "DSSS_" ~ args[1]; 
    152153            mkdirP(srcDir); 
    153             writefln("Building in %s", srcDir); 
     154            writefln("Working in %s", srcDir); 
    154155             
    155156            // 2) chdir 
     
    157158            chdir(srcDir); 
    158159             
     160            // make sure the directory gets removed 
     161            scope(exit) { 
     162                chdir(origcwd); 
     163                rmRecursive(srcDir); 
     164            } 
     165             
    159166            // 3) get sources 
    160167            if (!getSources(args[1], conf)) return 1; 
    161168            srcDir = getcwd(); 
    162169             
    163             // 4) make sure it's not installed 
    164             uninstall(args[1..2]); 
    165              
    166             // 5) install prerequisites 
    167             char[][] netcmd; 
    168             netcmd ~= "deps"; 
    169             int netret = net(netcmd); 
    170             if (netret) return netret; 
    171             chdir(srcDir); 
    172              
    173             // 6) build 
    174             DSSSConf dconf = readConfig(null); 
    175             int buildret = build(args[2..$], dconf); 
    176             if (buildret) return buildret; 
    177              
    178             // 7) install 
    179             return install(args[2..$]); 
     170            // if we're just fetching, make the archive 
     171            if (args[0] == "fetch") { 
     172                char[] archname = args[1] ~ ".tar.gz"; 
     173                 
     174                // compress 
     175                version (Windows) { 
     176                    system("bsdtar zcf " ~ archname ~ " ~ std.string.join( 
     177                        listdir(".", RegExp(r"^[^\.]")), 
     178                        " ")); 
     179                } else { 
     180                    system("tar -cf - * | gzip -c > " ~ archname); 
     181                } 
     182                 
     183                // move into place 
     184                std.file.rename(archname, 
     185                                origcwd ~ std.path.sep ~ archname); 
     186                 
     187                writefln("Archive %s created.", archname); 
     188                return 0; 
     189            } else { 
     190                // 4) make sure it's not installed 
     191                uninstall(args[1..2]); 
     192             
     193                // 5) install prerequisites 
     194                char[][] netcmd; 
     195                netcmd ~= "deps"; 
     196                int netret = net(netcmd); 
     197                if (netret) return netret; 
     198                chdir(srcDir); 
     199             
     200                // 6) build 
     201                DSSSConf dconf = readConfig(null); 
     202                int buildret = build(args[2..$], dconf); 
     203                if (buildret) return buildret; 
     204             
     205                // 7) install 
     206                return install(args[2..$]); 
     207            } 
    180208        } 
    181209