|
From: | Dale Miller |
Subject: | Re: Importing Empty Directories |
Date: | Wed, 13 Dec 2000 12:54:54 -0600 |
Hi!Manish,I am working on Solaris. Whenever I do an import, all the empty directories
are pruned (though they contain empty sub-directories). Is there any way by
which I can import all the directories present in a project? Please let me
know as soon as possible.
I wrote a program that creates a .keepme file in any empty directories
as discussed in http://cvshome.org/docs/manual/cvs_7.html#SEC69
Usage:
find_empty_directories.plx -path=/directory/to/start/at
[-action=""
This program finds all empty directories and identifies where
a ".keepme" should be present so a "cvs export" command will
create the directory.
It also identifies ".keepme" files that exist in non-empty
directories that could be removed.
If -action="" is used a ".keepme" file containing "keepme"
will be created. -action="" should not be used with a CVS
repository path
Here is my perl program:
--------------------- cut here --------------------------
#!/usr/local/bin/perl -ws
#
# $Id: find_empty_directories.plx,v 1.2 2000/12/13 18:53:10 miller
Exp $
#
# See sub usage for information about this program
#
$path = "" unless defined $path;
$action = "" unless defined $action;
@ls_result = ""; # used only once
if ($path eq "") {
&usage("Error: -path must be defined");
exit 1;
}
if (! -d $path) {
&usage("Error: -path=$path is not a directory");
exit 1;
}
if (!(($action eq "list") or ($action eq "create"))) {
&usage("Error: -action must be list or create");
exit 1;
}
sub usage {
print "\nUsage:\n";
print " $0 -path=/directory/to/start/at [-action=""
print "This program finds all empty directories and identifies
where\n";
print "a \".keepme\" should be present so a \"cvs export\"
command will\n";
print "create the directory.\n\n";
print "It also identifies \".keepme\" files that exist
in non-empty\n";
print "directories that could be removed.\n\n";
print "If -action="" is used a \".keepme\" file containing
\"keepme\"\n";
print "will be created. -action="" should not
be used with a CVS\n";
print "repository path\n\n";
print "@_\n";
}
@dirlist = `find $path -type d -print`;
#print "@dirlist";
foreach (@dirlist) {
chomp;
# -- get a list of all files (including hidden files)
but
# -- do not count . and ..
# -- if the number of files found is 0 the directory is
empty
$ls_length = grep {!/^\.{1,2}$/} @ls_result = `ls -a $_`;
if ($ls_length == 0) { # directory contains
only . and ..
if (! -e "$_/.keepme") {
if ($action eq "create")
{
print "creating $_/.keepme file\n";
`echo keepme >$_/.keepme; chmod 444 $_/.keepme`;
} else {
print "$_/.keepme should be added\n";
}
next;
}
}
if ($ls_length > 1) { # directory should
not have a .keepme
if (-e "$_/.keepme") {
print "$_/.keepme
should be removed\n";
}
}
}
------------------- end of program -------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |