Beispiel #1
0
        /// <summary>
        /// Exports the contents a layer or sandbox to the specified directory. Only the files and
        /// registry keys that were changed are exported.
        /// </summary>
        /// <param name="path">The path to the layer or sandbox.</param>
        /// <param name="exportPath">The path of the exported files. This directory will be created and must not already exist.</param>
        /// <param name="layers">A list of parent layers.</param>
        public static void ExportLayer(string path, string exportPath, IList <Layer> layers)
        {
            path = Path.GetFullPath(path);
            if (Directory.Exists(exportPath))
            {
                throw new IOException(string.Format("Directory {0} already exists.", exportPath));
            }

            Directory.CreateDirectory(exportPath);
            try
            {
                using (var info = new DriverInfoHelper())
                    using (var descriptors = new LayerHelper(layers))
                    {
                        StorageFunctions.ActivateLayer(ref info.Data, path);
                        try
                        {
                            StorageFunctions.ExportLayer(ref info.Data, path, exportPath, descriptors.Data, descriptors.Data.Length);
                        }
                        finally
                        {
                            StorageFunctions.DeactivateLayer(ref info.Data, path);
                        }
                    }
            }
            catch (Exception)
            {
                Directory.Delete(exportPath, true);
                throw;
            }
        }
Beispiel #2
0
            internal MountedSandbox(string path, IList <Layer> layers)
            {
                using (var info = new DriverInfoHelper())
                    using (var descriptors = new LayerHelper(layers))
                    {
                        StorageFunctions.ActivateLayer(ref info.Data, path);
                        try
                        {
                            StorageFunctions.PrepareLayer(ref info.Data, path, descriptors.Data, descriptors.Data.Length);
                            var mountPath = new StringBuilder(260);
                            var length    = new UIntPtr((uint)mountPath.Capacity);
                            StorageFunctions.GetLayerMountPath(ref info.Data, path, ref length, mountPath);
                            _mountPath = mountPath.ToString();
                        }
                        catch (Exception)
                        {
                            StorageFunctions.DeactivateLayer(ref info.Data, path);
                            throw;
                        }
                    }

                _path = path;
            }