Skip to content

Commit

Permalink
Bug-fixes: when clicking 'Duplicate Server', the new server's setting…
Browse files Browse the repository at this point in the history
…s were not being saved, so would be reset to blank after restarting system preferences. After clicking 'Duplicate Server' for a server with a non-blank username, the new server would get stuck in Retrying mode on first startup; this was because the new server was being configured with a log file located in the user log dir instead of the root log dir. Updated Readme file for 2.4.1 release.
  • Loading branch information
mckenfra committed Nov 10, 2015
1 parent ec66d49 commit 096aa6c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
7 changes: 3 additions & 4 deletions PostgreSQL/Classes/PGPrefsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ - (void)userDidRenameServer:(NSString *)name
AuthorizationRef authorization = [self authorize];
if (!authorization) return;

PGServerAction finalAction = server.running ? PGServerStart : PGServerCreate;
PGServerAction finalAction = server.started ? PGServerStart : PGServerCreate;
BackgroundThread(^{
// First stop and delete the existing server
[self.serverController runAction:PGServerDelete server:server authorization:authorization succeeded:^{
Expand Down Expand Up @@ -253,9 +253,8 @@ - (void)userDidDuplicateServer
if (!self.server) return;

// Create the server and copy over the settings
PGServer *server = [self.dataStore addServerWithName:self.server.shortName];
PGServer *server = [self.dataStore addServerWithName:self.server.shortName settings:self.server.settings];
if (!server) return;
[self.serverController setSettings:self.server.settings forServer:server];

// Get the new servers list after add
self.servers = self.dataStore.servers;
Expand Down Expand Up @@ -385,7 +384,7 @@ - (void)userDidApplySettings
AuthorizationRef authorization = [self authorize];
if (!authorization) return;

PGServerAction finalAction = server.running ? PGServerStart : PGServerCreate;
PGServerAction finalAction = server.started ? PGServerStart : PGServerCreate;
BackgroundThread(^{
if (!server.dirtySettings) return;

Expand Down
4 changes: 2 additions & 2 deletions PostgreSQL/Classes/PGServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ ServerStartupDescription(PGServerStartup value)
/// If YES, this server is starting or stopping
@property (nonatomic) BOOL processing;

/// If YES, this server is starting, started or retrying
@property (nonatomic, readonly) BOOL running;
/// If YES, this server is started or retrying
@property (nonatomic, readonly) BOOL started;

/// Any error that has been thrown when carrying out a server action
@property (nonatomic, strong) NSString *error;
Expand Down
8 changes: 3 additions & 5 deletions PostgreSQL/Classes/PGServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ - (id)initWithName:(NSString *)name domain:(NSString *)domain settings:(PGServer
self.domain = domain;
self.settings = settings;
self.dirtySettings = [PGServerSettings settingsWithSettings:settings];
self.dirtySettings = nil;
self.status = PGServerStatusUnknown;
self.error = nil;
}
Expand Down Expand Up @@ -264,10 +263,9 @@ - (void)setProperties:(NSDictionary *)properties
if (properties[PGServerStartupKey]) self.settings.startup = ToServerStartup(properties[PGServerStartupKey]);
}

- (BOOL)running
- (BOOL)started
{
return _status == PGServerStarting ||
_status == PGServerStarted ||
return _status == PGServerStarted ||
_status == PGServerRetrying;
}

Expand Down Expand Up @@ -326,7 +324,7 @@ - (NSString *)daemonLog
if (!self.external) {

// If started, use the context the server was loaded in. Otherwise, use the default.
BOOL root = self.running ? self.daemonLoadedForAllUsers : self.daemonForAllUsers;
BOOL root = self.started ? self.daemonLoadedForAllUsers : self.daemonForAllUsers;
NSString *logDir = root ? PGLaunchdDaemonLogRootDir : PGLaunchdDaemonLogUserDir;
return [NSString stringWithFormat:@"%@/%@.log", logDir, self.daemonName];

Expand Down
9 changes: 9 additions & 0 deletions PostgreSQL/Classes/PGServerDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
*/
- (PGServer *)addServerWithName:(NSString *)name;

/**
* Create a new server with specified name and settings, and add to saved server list.
*
* Note if another server exists with the same name, then (1), (2), (3), etc. is added to the name.
*
* @return a new server with the specified name and settings
*/
- (PGServer *)addServerWithName:(NSString *)name settings:(PGServerSettings *)settings;

/**
* Save server to data store
*
Expand Down
7 changes: 6 additions & 1 deletion PostgreSQL/Classes/PGServerDataStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ - (PGServer *)addServer
}

- (PGServer *)addServerWithName:(NSString *)prefix
{
return [self addServerWithName:prefix settings:nil];
}

- (PGServer *)addServerWithName:(NSString *)prefix settings:(PGServerSettings *)settings
{
if (!NonBlank(prefix)) prefix = PGServerDefaultName;
NSString *name = [self unusedServerNameWithPrefix:prefix];
PGServer *server = [self.serverController serverFromSettings:nil name:name domain:PGPrefsAppID];
PGServer *server = [self.serverController serverFromSettings:settings name:name domain:PGPrefsAppID];
if (!server) return nil;

[self addToCache:server];
Expand Down
11 changes: 11 additions & 0 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ However, from version 2.1 onwards, Postgre Preferences automatically detects and
</tr>
</thead>
<tbody>
<tr>
<td>v2.4.1</td>
<td>10-Nov 2015</td>
<td>Bug-fix release
<ul>
<li>Fixed unable to start server because username incorrectly marked as invalid</li>
<li>Fixed unable to start server after clicking 'Duplicate Server'</li>
<li>Fixed server settings not saved after clicking 'Duplicate Server'</li>
</ul>
</td>
</tr>
<tr>
<td>v2.4</td>
<td>30-Aug 2015</td>
Expand Down

0 comments on commit 096aa6c

Please sign in to comment.