private StartupMode detectMode()

in src/main/java/org/apache/sling/launchpad/base/impl/StartupManager.java [128:178]


    private StartupMode detectMode(final String osgiStorageDir) {
        final File dataFile = new File(this.confDir, DATA_FILE);
        if (dataFile.exists()) {

            FileReader fis = null;
            try {
                final long selfStamp = this.getSelfTimestamp();
                if (selfStamp > 0) {

                    fis = new FileReader(dataFile);
                    final char[] txt = new char[128];
                    final int len = fis.read(txt);
                    final String value = new String(txt, 0, len);

                    final long storedStamp = Long.parseLong(value);

                    logger.log(Logger.LOG_INFO, String.format("Stored startup timestamp: %s", storedStamp));

                    return (storedStamp >= selfStamp ? StartupMode.RESTART : StartupMode.UPDATE);
                }

            } catch (final NumberFormatException nfe) {
                // probably still the old value, fallback to assume not
                // installed
                return StartupMode.RESTART;

            } catch (final IOException ioe) {
                logger.log(Logger.LOG_ERROR,
                    "IOException during reading of installed flag.", ioe);

            } finally {
                if (fis != null) {
                    try { fis.close(); } catch (IOException ignore) {}
                }
            }
        } else {
            // check for old data file
            // this is a little bit hacky as we have to directly look into
            // the Apache Felix bundle cache. However, as we know that older
            // versions did use Felix this is fine.
            final File felixDir = new File(osgiStorageDir);
            final File oldFile = new File(felixDir, OLD_DATA_FILE);
            if ( oldFile.exists() ) {
                // this is an update - remove old file
                oldFile.delete();
                return StartupMode.UPDATE;
            }
        }
        // not installed yet - fallback
        return StartupMode.INSTALL;
    }