Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5850209

Browse files
committed
WINEDIT: make psql create home (%APPDATA%\postgresql) directory
when it uses default path to the history file and this directory doesn't exist. Fixes PGPRO-1392
1 parent 34654a5 commit 5850209

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/bin/psql/input.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
#ifndef WIN32
1111
#include <unistd.h>
12+
#else
13+
#include <sys/types.h>
14+
#include <sys/stat.h>
15+
#include <errno.h>
1216
#endif
1317
#include <fcntl.h>
1418
#include <limits.h>
@@ -366,7 +370,6 @@ initializeInput(int flags)
366370
history_lines_added = 0;
367371

368372
histfile = GetVariable(pset.vars, "HISTFILE");
369-
370373
if (histfile == NULL)
371374
{
372375
char *envhist;
@@ -380,14 +383,24 @@ initializeInput(int flags)
380383
{
381384
if (get_home_path(home))
382385
#ifdef HAVE_WIN32_LIBEDIT
386+
{
387+
struct _stat buffer;
383388
psql_history = psprintf("%s\\%s", home, PSQLHISTORY);
389+
/* Check if home exists and create it if needed,
390+
because there is no guarantee that it exits on Win32 */
391+
if (_stat(home,&buffer)!=0 && errno == ENOENT)
392+
{
393+
_mkdir(home);
394+
}
395+
}
384396
#else
385397
psql_history = psprintf("%s/%s", home, PSQLHISTORY);
386398
#endif
387399
}
388400
else
389401
{
390402
psql_history = pg_strdup(histfile);
403+
fprintf(stderr,"Expanding tilde\n");
391404
expand_tilde(&psql_history);
392405
}
393406

0 commit comments

Comments
 (0)