Skip to content

Commit

Permalink
path fix for application support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnycrab committed Sep 4, 2014
1 parent 47cdf43 commit 7ab8b1b
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 18 deletions.
41 changes: 34 additions & 7 deletions src/core/search/SearchStore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/search/SearchStore.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 37 additions & 7 deletions src/core/search/SearchStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference path='../../../ts-definitions/node/node.d.ts' />
/// <reference path='../../main.d.ts' />

import childProcess = require('child_process');
import fs = require('fs');
import fs = require('fs-extra');
import path = require('path');

import AppQuitHandlerInterface = require('../utils/interfaces/AppQuitHandlerInterface');
Expand Down Expand Up @@ -169,38 +169,68 @@ class SearchStore implements SearchStoreInterface {
/**
* Returns the arguments the database server should start with. The following options are currently included:
*
* - __-p__: The path where elasticsearch should save it's process id
* - __-p__: The path where elasticsearch should save its process id
* - __-Des.config__: The path to the config file
* - __-Des.path.data__: The path where the indexes should be stored
* * - __-Des.logger.level__: The level of the logger
*
* If we are in node-webkit and the config-file does not exist in Peeriod's specific application data path,
* it is dumped there. This is to ensure elasticsearch's whitespace problem in paths, as we have no control over
* where users store their applications.
*
* @method core.search.SearchStore~_getDatabaseServerProcessArgs
*
* @returns {Array<string>}
*/
private _getDatabaseServerProcessArgs ():Array<string> {
var configPath:string = path.resolve(__dirname, '../../', this._config.get('search.searchStoreConfig'));
var storagePath:string = path.resolve(__dirname, '../../', this._config.get('search.databasePath'));
var originalConfigPath:string = path.resolve(__dirname, '../../', this._config.get('search.searchStoreConfig'));
var storagePath:string = null;
var configPath:string = null;

if (process.env.IS_NODE_WEBKIT) {
var destinationConfigPath:string = path.resolve(this._config.get('app.dataPath'), '../../Peeriod', this._config.get('search.searchStoreConfig'));

if (!fs.existsSync(destinationConfigPath)) {
var origContents:string = fs.readFileSync(originalConfigPath, {encoding: 'utf8'});

fs.outputFileSync(destinationConfigPath, origContents);
}

configPath = destinationConfigPath;
storagePath = path.resolve(this._config.get('app.dataPath'), '../../Peeriod', this._config.get('search.databasePath'));
}
else {
storagePath = path.resolve(__dirname, '../../', this._config.get('search.databasePath'));
configPath = originalConfigPath;
}

return [
'-p',
this._getDatabaseServerProcessIdPath(),
('-Des.config=' + configPath),
('-Des.path.data=' + storagePath),
('-Des.logger.level=DEBUG'),
//('-Des.logger.level=DEBUG'),
'-d'
];
}

/**
* Returns the path where to look up the database server process id.
*
* This is in the database server module path when no node-webkit is used.
* Otherwise it's the os-specific appDataPath.
*
* @method core.search.SearchStore~_getDatabaseServerProcessIdPath
*
* @returns {string}
*/
private _getDatabaseServerProcessIdPath ():string {
return path.join(this._getDatabaseServerModulePath(), this._config.get('search.pidFilename'));
if (!process.env.IS_NODE_WEBKIT) {
return path.join(this._getDatabaseServerModulePath(), this._config.get('search.pidFilename'));
}
else {
return path.resolve(this._config.get('app.dataPath'), '../../Peeriod', this._config.get('search.pidFilename'));
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ab8b1b

Please sign in to comment.