OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
/// <summary>
/// Searches through the files in the archive for the control file, and reads it.
/// We must read the control file first, in order to know which regions are available.
/// </summary>
/// <remarks>
/// In most cases the control file *is* first, since that's how we create archives. However,
/// it's possible that someone rewrote the archive externally so we can't rely on this fact.
/// </remarks>
/// <param name="archive"></param>
/// <param name="dearchivedScenes"></param>
Searches through the files in the archive for the control file, and reads it.
We must read the control file first, in order to know which regions are available.
Searches through the files in the archive for the control file and reads it . We must read the control file first in order to know which regions are available .
private void FindAndLoadControlFile(out TarArchiveReader archive, out DearchiveScenesInfo dearchivedScenes)
        {
            archive = new TarArchiveReader(m_loadStream);
            dearchivedScenes = new DearchiveScenesInfo();
            string filePath;
            byte[] data;
            TarArchiveReader.TarEntryType entryType;
            bool firstFile = true;
            while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    continue;
                if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                {
                    LoadControlFile(filePath, data, dearchivedScenes);
                    ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup();
                    SceneManager.Instance.ForEachScene(delegate(Scene scene2)
                    {
                        simulatorScenes.AddScene(scene2);
                    });
                    simulatorScenes.CalcSceneLocations();
                    dearchivedScenes.SetSimulatorScenes(m_rootScene, simulatorScenes);
                    if (!firstFile)
                    {
                        m_log.Warn("Control file wasn't the first file in the archive");
                        if (m_loadStream.CanSeek)
                        {
                            m_loadStream.Seek(0, SeekOrigin.Begin);
                        }
                        else if (m_loadPath != null)
                        {
                            archive.Close();
                            archive = null;
                            m_loadStream.Close();
                            m_loadStream = null;
                            m_loadStream = new GZipStream(ArchiveHelpers.GetStream(m_loadPath), CompressionMode.Decompress);
                            archive = new TarArchiveReader(m_loadStream);
                        }
                        else
                        {
                            throw new Exception("Error reading archive: control file wasn't the first file, and the input stream doesn't allow seeking");
                        }
                    }
                    return;
                }
                firstFile = false;
            }
            throw new Exception("Control file not found");
        }
private void FindAndLoadControlFile ( out TarArchiveReader archive , out DearchiveScenesInfo dearchivedScenes ) { archive = new TarArchiveReader ( m_loadStream ) ; dearchivedScenes = new DearchiveScenesInfo ( ) ; string filePath ; byte [ ] data ; TarArchiveReader . TarEntryType entryType ; bool firstFile = true ; while ( ( data = archive . ReadEntry ( out filePath , out entryType ) ) != null ) { if ( TarArchiveReader . TarEntryType . TYPE_DIRECTORY == entryType ) continue ; if ( filePath == ArchiveConstants . CONTROL_FILE_PATH ) { LoadControlFile ( filePath , data , dearchivedScenes ) ; ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup ( ) ; SceneManager . Instance . ForEachScene ( delegate ( Scene scene2 ) { simulatorScenes . AddScene ( scene2 ) ; } ) ; simulatorScenes . CalcSceneLocations ( ) ; dearchivedScenes . SetSimulatorScenes ( m_rootScene , simulatorScenes ) ; if ( ! firstFile ) { m_log . Warn ( " " ) ; if ( m_loadStream . CanSeek ) { m_loadStream . Seek ( 0 , SeekOrigin . Begin ) ; } else if ( m_loadPath != null ) { archive . Close ( ) ; archive = null ; m_loadStream . Close ( ) ; m_loadStream = null ; m_loadStream = new GZipStream ( ArchiveHelpers . GetStream ( m_loadPath ) , CompressionMode . Decompress ) ; archive = new TarArchiveReader ( m_loadStream ) ; } else { throw new Exception ( " " ) ; } } return ; } firstFile = false ; } throw new Exception ( " " ) ; }
Searches through the files in the archive for the control file, and reads it.
Searches through the files in the archive for the control file and reads it .
// Find which scenes are available in the simulator // If the control file wasn't the first file then reset the read pointer // There isn't currently a scenario where this happens, but it's best to add a check just in case
TarArchiveReader
out
DearchiveScenesInfo
out
archive
None
dearchivedScenes
None
remarks
In most cases the control file *is* first, since that's how we create archives. However,
it's possible that someone rewrote the archive externally so we can't rely on this fact.
In most cases the control file * is * first since that ' s how we create archives . However it ' s possible that someone rewrote the archive externally so we can ' t rely on this fact .