Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.8 KiB

  1. @echo off
  2. for %%i in (%0.cmd) do perl -w -x %%~dp$PATH:i%0.cmd %*
  3. goto :eof
  4. #!perl
  5. # line 7
  6. #
  7. # FileName: sdout.cmd
  8. #
  9. # Usage = sdout [-v] [-o] filename...
  10. #
  11. # This script allows for more graceful offline operation of SD. It tries
  12. # to run SD EDIT on the supplied filenames. If SD fails, then the file
  13. # is made writable and the filename is added to the sd.offline file in the
  14. # root of the depot.
  15. #
  16. # sdout with no arguments provides a list of the files which are currently
  17. # marked for offline editing.
  18. #
  19. # Once network connectivity is restored, sdonline.cmd will cleanup the
  20. # sd.offline files and check the files out properly.
  21. #
  22. #
  23. use Cwd;
  24. use Getopt::Std;
  25. use File::Spec;
  26. #
  27. # initialize globals
  28. #
  29. $opt_v = 0;
  30. $opt_o = 0;
  31. %offline_depots = ();
  32. $Usage = "
  33. USAGE: $0 [-v] [-o] filename [filename..]
  34. -v Verbose output
  35. -o Offline assumed\n";
  36. #
  37. # given a path, finds the directory above it that contains SD.INI
  38. # (and SD.OFFLINE)
  39. # pathname should be passed as a list of components rather than as
  40. # a string
  41. #
  42. sub findSDroot {
  43. my $temppath;
  44. while (@_) {
  45. $temppath = join('\\', @_);
  46. $opt_v and print "checking $temppath for SD.INI\n";
  47. if (-e ($temppath . "\\sd.ini")) {
  48. return($temppath);
  49. }
  50. #
  51. # remove the last component
  52. #
  53. pop;
  54. }
  55. }
  56. #
  57. # process options
  58. #
  59. getopts('vo') or die $Usage;
  60. if ($opt_v) {
  61. print "Verbose mode\n";
  62. $opt_o and print "Offline mode forced\n";
  63. }
  64. if (@ARGV) {
  65. for (@ARGV) {
  66. FILEARG:
  67. foreach $file (glob) {
  68. #
  69. # Get the fully qualified pathname for the supplied file
  70. #
  71. -e $file or die "file $file does not exist!\n";
  72. $pathname = File::Spec::canonpath(cwd() . "\\$file");
  73. $opt_v and print "filename is $pathname\n";
  74. @components = split(/[\/\\]/, $pathname);
  75. $opt_v and print "components are @components\n";
  76. pop @components; # get rid of the filename
  77. #
  78. # find the root of this SD project
  79. #
  80. $SDRoot = findSDroot(@components);
  81. $SDRoot or die "no SD.INI found along the path to $_\n";
  82. $opt_v and print "Found SD.INI at $SDRoot\n";
  83. #
  84. # if the root is not already known to be offline, and we're
  85. # not running in forced offline mode, try and use SD to check
  86. # the file out.
  87. #
  88. unless ($opt_o || $offline_depots{$SDRoot}) {
  89. $opt_v and print "running SD EDIT $file\n";
  90. @sdout = `sd edit $file 2>&1`;
  91. $opt_v and print "sd edit returned $?\n";
  92. $opt_v and print "sd edit printed:\n@sdout\n";
  93. if ($?) {
  94. #
  95. # remember that this depot is offline so we don't
  96. # bother trying to connect on subsequent files.
  97. #
  98. $offline_depots{$SDRoot} = 1;
  99. } else {
  100. next FILEARG;
  101. }
  102. }
  103. #
  104. # open the sd.offline file and read it in
  105. #
  106. $fn = $SDRoot . "\\sd.offline";
  107. if (-e $fn) {
  108. $opt_v and print "opening file $fn\n";
  109. open(OFFLINEFILE, $fn) or die "couldn't open $fn: $!\n";
  110. @offlinefiles = <OFFLINEFILE>;
  111. foreach $file (@offlinefiles) {
  112. $opt_v and print "OFFLINE FILE: $file";
  113. chop $file;
  114. if ($file eq $pathname) {
  115. print "file $pathname is already marked as offline\n";
  116. next FILEARG;
  117. }
  118. }
  119. }
  120. #
  121. # the file is not in the offline file, so append it now
  122. #
  123. open(OFFLINEFILE, ">>$fn") or die "couldn't append to $fn: $!\n";
  124. $opt_v and print "appending $pathname to $fn\n";
  125. print OFFLINEFILE $pathname,"\n";
  126. #
  127. # finally remove the read-only bit
  128. #
  129. `attrib -r $pathname`;
  130. print "file $pathname is now marked as offline\n";
  131. }
  132. }
  133. } else {
  134. #
  135. # no file arguments passed, just display the list of currently
  136. # offline files
  137. #
  138. @components = split(/[\/\\]/, cwd());
  139. $SDRoot = findSDroot(@components) or die "no SD.INI found in path";
  140. $fn = $SDRoot . "\\sd.offline";
  141. if (-e $fn) {
  142. $opt_v and print "opening file $fn\n";
  143. open(OFFLINEFILE, $fn) or die "couldn't open $fn: $!\n";
  144. @offlinefiles = <OFFLINEFILE>;
  145. print "Currently offline files:\n";
  146. foreach $file (@offlinefiles) {
  147. chop $file and print "\t$file\n";
  148. }
  149. } else {
  150. print "There are currently no offline files\n";
  151. }
  152. }