Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
55a92063
Commit
55a92063
authored
Jan 09, 2004
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow psql to handle tilde user expansion for file names.
Zach Irmen
parent
38081fd0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
4 deletions
+83
-4
src/bin/psql/command.c
src/bin/psql/command.c
+15
-1
src/bin/psql/common.c
src/bin/psql/common.c
+63
-1
src/bin/psql/common.h
src/bin/psql/common.h
+3
-1
src/bin/psql/copy.c
src/bin/psql/copy.c
+2
-1
No files found.
src/bin/psql/command.c
View file @
55a92063
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.10
8 2003/12/01 22:21:54
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.10
9 2004/01/09 21:12:20
momjian Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "command.h"
#include "command.h"
...
@@ -413,6 +413,7 @@ exec_command(const char *cmd,
...
@@ -413,6 +413,7 @@ exec_command(const char *cmd,
else
else
{
{
fname
=
scan_option
(
&
string
,
OT_NORMAL
,
NULL
,
true
);
fname
=
scan_option
(
&
string
,
OT_NORMAL
,
NULL
,
true
);
expand_tilde
(
&
fname
);
status
=
do_edit
(
fname
,
query_buf
)
?
CMD_NEWEDIT
:
CMD_ERROR
;
status
=
do_edit
(
fname
,
query_buf
)
?
CMD_NEWEDIT
:
CMD_ERROR
;
free
(
fname
);
free
(
fname
);
}
}
...
@@ -494,7 +495,10 @@ exec_command(const char *cmd,
...
@@ -494,7 +495,10 @@ exec_command(const char *cmd,
if
(
!
fname
)
if
(
!
fname
)
pset
.
gfname
=
NULL
;
pset
.
gfname
=
NULL
;
else
else
{
expand_tilde
(
&
fname
);
pset
.
gfname
=
xstrdup
(
fname
);
pset
.
gfname
=
xstrdup
(
fname
);
}
free
(
fname
);
free
(
fname
);
status
=
CMD_SEND
;
status
=
CMD_SEND
;
}
}
...
@@ -531,6 +535,7 @@ exec_command(const char *cmd,
...
@@ -531,6 +535,7 @@ exec_command(const char *cmd,
}
}
else
else
{
{
expand_tilde
(
&
fname
);
success
=
(
process_file
(
fname
)
==
EXIT_SUCCESS
);
success
=
(
process_file
(
fname
)
==
EXIT_SUCCESS
);
free
(
fname
);
free
(
fname
);
}
}
...
@@ -561,7 +566,10 @@ exec_command(const char *cmd,
...
@@ -561,7 +566,10 @@ exec_command(const char *cmd,
success
=
false
;
success
=
false
;
}
}
else
else
{
expand_tilde
(
&
opt2
);
success
=
do_lo_export
(
opt1
,
opt2
);
success
=
do_lo_export
(
opt1
,
opt2
);
}
}
}
else
if
(
strcmp
(
cmd
+
3
,
"import"
)
==
0
)
else
if
(
strcmp
(
cmd
+
3
,
"import"
)
==
0
)
...
@@ -572,7 +580,10 @@ exec_command(const char *cmd,
...
@@ -572,7 +580,10 @@ exec_command(const char *cmd,
success
=
false
;
success
=
false
;
}
}
else
else
{
expand_tilde
(
&
opt1
);
success
=
do_lo_import
(
opt1
,
opt2
);
success
=
do_lo_import
(
opt1
,
opt2
);
}
}
}
else
if
(
strcmp
(
cmd
+
3
,
"list"
)
==
0
)
else
if
(
strcmp
(
cmd
+
3
,
"list"
)
==
0
)
...
@@ -602,6 +613,7 @@ exec_command(const char *cmd,
...
@@ -602,6 +613,7 @@ exec_command(const char *cmd,
{
{
char
*
fname
=
scan_option
(
&
string
,
OT_FILEPIPE
,
NULL
,
true
);
char
*
fname
=
scan_option
(
&
string
,
OT_FILEPIPE
,
NULL
,
true
);
expand_tilde
(
&
fname
);
success
=
setQFout
(
fname
);
success
=
setQFout
(
fname
);
free
(
fname
);
free
(
fname
);
}
}
...
@@ -653,6 +665,7 @@ exec_command(const char *cmd,
...
@@ -653,6 +665,7 @@ exec_command(const char *cmd,
{
{
char
*
fname
=
scan_option
(
&
string
,
OT_NORMAL
,
NULL
,
true
);
char
*
fname
=
scan_option
(
&
string
,
OT_NORMAL
,
NULL
,
true
);
expand_tilde
(
&
fname
);
success
=
saveHistory
(
fname
?
fname
:
"/dev/tty"
);
success
=
saveHistory
(
fname
?
fname
:
"/dev/tty"
);
if
(
success
&&
!
quiet
&&
fname
)
if
(
success
&&
!
quiet
&&
fname
)
...
@@ -771,6 +784,7 @@ exec_command(const char *cmd,
...
@@ -771,6 +784,7 @@ exec_command(const char *cmd,
else
else
{
{
fname
=
scan_option
(
&
string
,
OT_FILEPIPE
,
NULL
,
true
);
fname
=
scan_option
(
&
string
,
OT_FILEPIPE
,
NULL
,
true
);
expand_tilde
(
&
fname
);
if
(
!
fname
)
if
(
!
fname
)
{
{
...
...
src/bin/psql/common.c
View file @
55a92063
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.7
8 2003/11/29 19:52:06 pgsql
Exp $
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.7
9 2004/01/09 21:12:20 momjian
Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "common.h"
#include "common.h"
...
@@ -814,3 +814,65 @@ session_username(void)
...
@@ -814,3 +814,65 @@ session_username(void)
else
else
return
PQuser
(
pset
.
db
);
return
PQuser
(
pset
.
db
);
}
}
/* expand_tilde
*
* substitute '~' with HOME or '~username' with username's home dir
*
*/
char
*
expand_tilde
(
char
**
filename
)
{
if
(
!
filename
||
!
(
*
filename
))
return
NULL
;
/* MSDOS uses tilde for short versions of long file names, so skip it. */
#ifndef WIN32
/* try tilde expansion */
if
(
**
filename
==
'~'
)
{
char
*
fn
;
char
*
home
;
char
oldp
,
*
p
;
struct
passwd
*
pw
;
fn
=
*
filename
;
home
=
NULL
;
p
=
fn
+
1
;
while
(
*
p
!=
'/'
&&
*
p
!=
'\0'
)
p
++
;
oldp
=
*
p
;
*
p
=
'\0'
;
if
(
*
(
fn
+
1
)
==
'\0'
)
home
=
getenv
(
"HOME"
);
else
if
((
pw
=
getpwnam
(
fn
+
1
))
!=
NULL
)
home
=
pw
->
pw_dir
;
*
p
=
oldp
;
if
(
home
)
{
char
*
newfn
;
newfn
=
malloc
(
strlen
(
home
)
+
strlen
(
p
)
+
1
);
if
(
!
newfn
)
{
psql_error
(
"out of memory
\n
"
);
exit
(
EXIT_FAILURE
);
}
strcpy
(
newfn
,
home
);
strcat
(
newfn
,
p
);
free
(
fn
);
*
filename
=
newfn
;
}
}
#endif
return
*
filename
;
}
src/bin/psql/common.h
View file @
55a92063
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.3
1 2003/12/01 22:14:4
0 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.3
2 2004/01/09 21:12:2
0 momjian Exp $
*/
*/
#ifndef COMMON_H
#ifndef COMMON_H
#define COMMON_H
#define COMMON_H
...
@@ -58,4 +58,6 @@ extern char parse_char(char **buf);
...
@@ -58,4 +58,6 @@ extern char parse_char(char **buf);
#define pclose(x) _pclose(x)
#define pclose(x) _pclose(x)
#endif
#endif
extern
char
*
expand_tilde
(
char
**
filename
);
#endif
/* COMMON_H */
#endif
/* COMMON_H */
src/bin/psql/copy.c
View file @
55a92063
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.3
5 2003/12/01 22:14:4
0 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.3
6 2004/01/09 21:12:2
0 momjian Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "copy.h"
#include "copy.h"
...
@@ -221,6 +221,7 @@ parse_slash_copy(const char *args)
...
@@ -221,6 +221,7 @@ parse_slash_copy(const char *args)
result
->
file
=
NULL
;
result
->
file
=
NULL
;
else
else
result
->
file
=
xstrdup
(
token
);
result
->
file
=
xstrdup
(
token
);
expand_tilde
(
&
result
->
file
);
token
=
strtokx
(
NULL
,
whitespace
,
NULL
,
NULL
,
token
=
strtokx
(
NULL
,
whitespace
,
NULL
,
NULL
,
0
,
false
,
pset
.
encoding
);
0
,
false
,
pset
.
encoding
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment