geek-li / redtamarin

Automatically exported from code.google.com/p/redtamarin
Other
1 stars 0 forks source link

OperatingSystem _parseLinuxReleaseFile() faill on CentOS #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
if the _parseLinuxReleaseFile() fail
the whole script returns

{{{
TypeError: Error #1010: A term is undefined and has no properties.
        at avmplus::OperatingSystem$/_parseLinuxReleaseFile()
        at avmplus::OperatingSystem$/getVendorDescriptionLinux()
        at avmplus::OperatingSystem$/getVendorDescriptionAll()
        at avmplus::OperatingSystem$/get vendorDescription()
        at avmplus.profiles::RedTamarinProfile/_ctor()
        at avmplus.profiles::RedTamarinProfile()
        at global$init()
        at global$init()
}}}

here what happen:

by default toplevel will run
{{{
System.profile = new RedTamarinProfile();
}}}

RedTamarinProfile call
{{{
_manufacturer         = OperatingSystem.vendor;
}}}

here when _parseLinuxReleaseFile() execute
if it fails, nothing will be able to run

we need to do different thing

1) we need to lazy init System.profile

toplevel shoudl NOT initialize it
but instead avmplus::System should do that

http://code.google.com/p/maashaack/source/browse/platform/shell/trunk/src/avmplu
s/System.as
{{{
        public static function get profile():Profile
        {
            if( _profile ) return _profile;

            var defaultProfile:Class = getClassByName( "avmplus.profiles.RedTamarinProfile" );

            if( defaultProfile )
            {
                _profile = new defaultProfile();
            }
        }
}}}

2) we should catch errors in _parseLinuxReleaseFile()

http://code.google.com/p/maashaack/source/browse/platform/shell/trunk/src/avmplu
s/OperatingSystem.as
{{{
        private static function _parseLinuxReleaseFile():void
        {
            var filename:String;
            var file:String;
            var i:uint;

            for( i=0; i<_linuxReleaseFiles.length; i++ )
            {
                filename = _linuxReleaseFiles[i];
                if( FileSystem.exists( filename ) )
                {
                    file = FileSystem.read( filename );
                    break;
                }
            }

            if( file )
            {
                /* note:
                   OK, here we assume a little too much
                   - line separator always "\n"
                   - lines always in the same order

                   tested and working on Ubuntu
                   but come back here later and improve the parsing
                */
                try
                {
                    var lines:Array          = file.split( "\n" );
                    _linuxDistribID          = lines[0].split( "=" )[1];
                    _linuxDistribRelease     = lines[1].split( "=" )[1];
                    _linuxDistribCodename    = lines[2].split( "=" )[1];
                    _linuxDistribDescription = lines[3].split( "=" )[1];

                    if( _linuxDistribDescription.indexOf( "\"" ) > -1 )
                    {
                        _linuxDistribDescription = _linuxDistribDescription.split( "\"" ).join( "" );
                    }
                }
                catch( e:Error )
                {
                    //do something here
                }
            }
            else
            {
                //set defaults if filename not found
                _linuxDistribID          = name;
                _linuxDistribRelease     = release;
                _linuxDistribCodename    = UNKNOWN;
                _linuxDistribDescription = "";
            }

        }
}}}

Original issue reported on code.google.com by zwetan on 24 Jul 2011 at 8:38

GoogleCodeExporter commented 9 years ago

Original comment by zwetan on 7 Aug 2011 at 12:43