[gnome-ostree] zdisks: Inherit from builddisks instead of copying
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-ostree] zdisks: Inherit from builddisks instead of copying
- Date: Tue, 16 Apr 2013 17:40:51 +0000 (UTC)
commit c0963a44ea26b74d1eab99aadf5c9b28035718a3
Author: Colin Walters <walters verbum org>
Date: Tue Apr 16 12:37:32 2013 -0400
zdisks: Inherit from builddisks instead of copying
This reduces code duplication a lot; furthermore, we want zdisks to
make a disk image from scratch so it's small, whereas builddisks will
be incremental and feed the testing suite.
src/js/tasks/task-builddisks.js | 13 +++++-
src/js/tasks/task-zdisks.js | 87 +++++++++--------------------------------
2 files changed, 29 insertions(+), 71 deletions(-)
---
diff --git a/src/js/tasks/task-builddisks.js b/src/js/tasks/task-builddisks.js
index c79ca4c..db50bfd 100644
--- a/src/js/tasks/task-builddisks.js
+++ b/src/js/tasks/task-builddisks.js
@@ -46,10 +46,13 @@ const TaskBuildDisks = new Lang.Class({
// Legacy
_VERSION_RE: /^(\d+)\.(\d+)$/,
+ _imageSubdir: 'images',
+ _inheritPreviousDisk: true,
+
execute: function(cancellable) {
let subworkdir = Gio.File.new_for_path('.');
- let baseImageDir = this.workdir.get_child('images');
+ let baseImageDir = this.workdir.resolve_relative_path(this._imageSubdir);
GSystem.file_ensure_directory(baseImageDir, true, cancellable);
let currentImageLink = baseImageDir.get_child('current');
let previousImageLink = baseImageDir.get_child('previous');
@@ -84,7 +87,7 @@ const TaskBuildDisks = new Lang.Class({
let diskPath = workImageDir.get_child(diskName);
let prevPath = currentImageLink.get_child(diskName);
GSystem.shutil_rm_rf(diskPath, cancellable);
- if (prevPath.query_exists(null)) {
+ if (this._inheritPreviousDisk && prevPath.query_exists(null)) {
LibQA.copyDisk(prevPath, diskPath, cancellable);
} else {
LibQA.createDisk(diskPath, cancellable);
@@ -106,6 +109,8 @@ const TaskBuildDisks = new Lang.Class({
gfmnt.umount(cancellable);
}
LibQA.bootloaderInstall(diskPath, subworkdir, osname, cancellable);
+
+ this._postDiskCreation(diskPath, cancellable);
}
GSystem.file_rename(workImageDir, targetImageDir, cancellable);
@@ -129,6 +134,10 @@ const TaskBuildDisks = new Lang.Class({
this._cleanOldVersions(baseImageDir, IMAGE_RETAIN_COUNT, cancellable);
},
+ _postDiskCreation: function(diskPath, cancellable) {
+ // Nothing, this is used by zdisks
+ },
+
_loadVersionsFrom: function(dir, cancellable) {
let e = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
cancellable);
let info;
diff --git a/src/js/tasks/task-zdisks.js b/src/js/tasks/task-zdisks.js
index 4cd6cec..4a0ad22 100644
--- a/src/js/tasks/task-zdisks.js
+++ b/src/js/tasks/task-zdisks.js
@@ -34,82 +34,31 @@ const JsonUtil = imports.jsonutil;
const JSUtil = imports.jsutil;
const GuestFish = imports.guestfish;
+const BuildDisks = imports.tasks['task-builddisks'];
+
const TaskZDisks = new Lang.Class({
Name: 'TaskZDisks',
- Extends: Task.TaskDef,
+ Extends: BuildDisks.TaskBuildDisks,
TaskName: "zdisks",
TaskAfter: ['builddisks'],
+ TaskScheduleMinSecs: 60*60, // Only do this once an hour
// Legacy
_VERSION_RE: /^(\d+)\.(\d+)$/,
- execute: function(cancellable) {
- let subworkdir = Gio.File.new_for_path('.');
-
- let baseImageDir = this.workdir.resolve_relative_path('images/z');
- GSystem.file_ensure_directory(baseImageDir, true, cancellable);
- let currentImageLink = baseImageDir.get_child('current');
-
- let sourceImageDir = this.workdir.get_child('images');
- let sourceCurrent = sourceImageDir.get_child('current');
- let sourceRevision = sourceCurrent.query_info('standard::symlink-target',
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
- cancellable).get_symlink_target();
- let targetImageDir = baseImageDir.get_child(sourceRevision);
- if (targetImageDir.query_exists(null)) {
- print("Already created " + targetImageDir.get_path());
- return;
- }
-
- let workImageDir = subworkdir.get_child('images');
- GSystem.file_ensure_directory(workImageDir, true, cancellable);
-
- let e = sourceCurrent.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
- cancellable);
- let info;
- while ((info = e.next_file(cancellable)) != null) {
- let name = info.get_name();
- if (!JSUtil.stringEndswith(name, '.qcow2'))
- continue;
- let inPath = e.get_child(info);
- let outPath = workImageDir.get_child(name + '.gz');
- let outStream = outPath.create(Gio.FileCreateFlags.REPLACE_DESTINATION, cancellable);
- let compressor = Gio.ZlibCompressor.new(Gio.ZlibCompressorFormat.GZIP, 7);
- let outConverter = Gio.ConverterOutputStream.new(outStream, compressor);
- let inStream = inPath.read(cancellable);
- outConverter.splice(inStream, Gio.OutputStreamSpliceFlags.CLOSE_SOURCE |
- Gio.OutputStreamSpliceFlags.CLOSE_TARGET, cancellable);
- }
-
- GSystem.file_rename(workImageDir, targetImageDir, cancellable);
-
- BuildUtil.atomicSymlinkSwap(currentImageLink, targetImageDir, cancellable);
-
- this._cleanOldVersions(baseImageDir, 1, cancellable);
- },
-
- _loadVersionsFrom: function(dir, cancellable) {
- let e = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
cancellable);
- let info;
- let results = [];
- while ((info = e.next_file(cancellable)) != null) {
- let name = info.get_name();
- let match = this._VERSION_RE.exec(name);
- if (!match)
- continue;
- results.push(name);
- }
- results.sort(BuildUtil.compareVersions);
- return results;
- },
-
- _cleanOldVersions: function(dir, retain, cancellable) {
- let versions = this._loadVersionsFrom(dir, cancellable);
- while (versions.length > retain) {
- let child = dir.get_child(versions.shift());
- GSystem.shutil_rm_rf(child, cancellable);
- }
- },
-
+ _imageSubdir: 'images/z',
+ _inheritPreviousDisk: false,
+
+ _postDiskCreation: function(diskPath, cancellable) {
+ let parent = diskPath.get_parent();
+ let outPath = parent.get_child(diskPath.get_basename() + '.gz');
+ let outStream = outPath.create(Gio.FileCreateFlags.REPLACE_DESTINATION, cancellable);
+ let compressor = Gio.ZlibCompressor.new(Gio.ZlibCompressorFormat.GZIP, 7);
+ let outConverter = Gio.ConverterOutputStream.new(outStream, compressor);
+ let inStream = diskPath.read(cancellable);
+ outConverter.splice(inStream, Gio.OutputStreamSpliceFlags.CLOSE_SOURCE |
+ Gio.OutputStreamSpliceFlags.CLOSE_TARGET, cancellable);
+ diskPath.delete(cancellable);
+ }
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]