1
0

move.ck 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*++
  2. Copyright (c) 2017 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. move.ck
  9. Abstract:
  10. This module implements package presentation based on moving files from
  11. storage into their final destination. This is useful if storage is not
  12. shared or containers are not in use, and the user doesn't want package
  13. contents duplicated.
  14. Author:
  15. Evan Green 17-Jul-2017
  16. Environment:
  17. Chalk
  18. --*/
  19. //
  20. // ------------------------------------------------------------------- Includes
  21. //
  22. from santa.config import config;
  23. from santa.file import cptree, mv, exists, isdir, mkdir, rmdir;
  24. from santa.presentation import Presentation, PresentationError;
  25. //
  26. // --------------------------------------------------------------------- Macros
  27. //
  28. //
  29. // ---------------------------------------------------------------- Definitions
  30. //
  31. //
  32. // ------------------------------------------------------ Data Type Definitions
  33. //
  34. //
  35. // ----------------------------------------------- Internal Function Prototypes
  36. //
  37. //
  38. // -------------------------------------------------------------------- Globals
  39. //
  40. //
  41. // ------------------------------------------------------------------ Functions
  42. //
  43. class CopyPresentation is Presentation {
  44. var _parameters;
  45. function
  46. create (
  47. parameters
  48. )
  49. /*++
  50. Routine Description:
  51. This routine creates a new presentation layer and initializes this
  52. instance's internal variables to represent it.
  53. Arguments:
  54. parameters - Supplies a dictionary of creation parameters.
  55. Return Value:
  56. None.
  57. --*/
  58. {
  59. _parameters = parameters.copy();
  60. this.type = "move";
  61. return;
  62. }
  63. function
  64. destroy (
  65. )
  66. /*++
  67. Routine Description:
  68. This routine destroys the presentation layer represented by this
  69. instance.
  70. Arguments:
  71. None.
  72. Return Value:
  73. None.
  74. --*/
  75. {
  76. return;
  77. }
  78. function
  79. load (
  80. parameters
  81. )
  82. /*++
  83. Routine Description:
  84. This routine initializes this instance to reflect the presentation
  85. identified by the given parameters.
  86. Arguments:
  87. parameters - Supplies a dictionary of parameters.
  88. Return Value:
  89. None.
  90. --*/
  91. {
  92. _parameters = parameters;
  93. this.type = "move";
  94. return;
  95. }
  96. function
  97. save (
  98. )
  99. /*++
  100. Routine Description:
  101. This routine returns the dictionary of state and identification needed
  102. to restore information about this presentation layer by other instances
  103. of this class.
  104. Arguments:
  105. None.
  106. Return Value:
  107. Returns a dictionary of parameters to save describing this instance.
  108. --*/
  109. {
  110. return _parameters;
  111. }
  112. function
  113. addFiles (
  114. controlDirectory,
  115. realm,
  116. files,
  117. conffiles,
  118. root
  119. )
  120. /*++
  121. Routine Description:
  122. This routine adds a set of files into the environment.
  123. Arguments:
  124. controlDirectory - Supplies the directory containing the control and
  125. initial data of the package.
  126. realm - Supplies the realm being operated on.
  127. files - Supplies the files to add.
  128. conffiles - Suppiles the dictionary of files not to clobber if they
  129. exist, or to copy directly if they do not.
  130. root - Supplies the root directory to install to.
  131. Return Value:
  132. None.
  133. --*/
  134. {
  135. var dest;
  136. var destdir = realm.containment.outerPath(root);
  137. var srcfile;
  138. var srcdir = controlDirectory + "/data";
  139. if (destdir.endsWith("/")) {
  140. destdir = destdir[0..-1];
  141. }
  142. //
  143. // First create all the directories.
  144. //
  145. for (file in files) {
  146. srcfile = "/".join([srcdir, file]);
  147. if (isdir(srcfile)) {
  148. mkdir("/".join([destdir, file]));
  149. }
  150. }
  151. for (file in files) {
  152. srcfile = "/".join([srcdir, file]);
  153. if (isdir(srcfile)) {
  154. continue;
  155. }
  156. dest = "/".join([destdir, file]);
  157. if ((conffiles.get(dest) != null) && (exists(dest))) {
  158. if (config.getKey("core.verbose")) {
  159. Core.print("Skipping pre-existing configuration file: %s" %
  160. dest);
  161. }
  162. continue;
  163. }
  164. mv(srcfile, dest);
  165. }
  166. //
  167. // Now remove all empty directories.
  168. //
  169. for (file in files) {
  170. srcfile = "/".join([srcdir, file]);
  171. if (isdir(srcfile)) {
  172. rmdir(srcfile);
  173. }
  174. }
  175. return;
  176. }
  177. }
  178. //
  179. // Define the globals needed so the module loader can pick up this class.
  180. //
  181. var description = "Copy-based installation";
  182. var presentation = CopyPresentation;
  183. //
  184. // --------------------------------------------------------- Internal Functions
  185. //