summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-08-30 17:37:17 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-08-30 17:37:17 +0200
commitd3cdae71d893eebaf9ab485fbcee33c0d6e280da (patch)
tree1a923c88cde6769da30e7909b026c07d00c92bab
parent64b70c220b1a413e500f2f7e04095cc902d3f7a6 (diff)
downloadcssh-d3cdae71d893eebaf9ab485fbcee33c0d6e280da.tar.gz
cssh-d3cdae71d893eebaf9ab485fbcee33c0d6e280da.tar.bz2
creating a basedir per host in recursive scp
-rw-r--r--src/cssh.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/cssh.c b/src/cssh.c
index bd53804..244d90e 100644
--- a/src/cssh.c
+++ b/src/cssh.c
@@ -971,7 +971,17 @@ int main( int argc, char *argv[] )
rc = push_dir_stack( &dir_stack[i], pwd );
- // TODO: directory should be a base per hostname[i]
+ size_t len = strlen( pwd ) + 2 + strlen( host[i] );
+ char *full_path = (char *)malloc( len );
+ if( full_path == NULL ) {
+ fprintf( stderr, "ERROR: Memory allocation failed for full path of basse directory for host '%s'\n",
+ host[i] );
+ free( pwd );
+ cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 );
+ exit( EXIT_FAILURE );
+ }
+ snprintf( full_path, len, "%s/%s", pwd, host[i] );
+ rc = push_dir_stack( &dir_stack[i], full_path );
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed remember initial base directory '%s' in directory stack\n",
@@ -981,6 +991,14 @@ int main( int argc, char *argv[] )
exit( EXIT_FAILURE );
}
free( pwd );
+
+ rc = mkdir( full_path, 0750 );
+ if( rc < 0 ) {
+ fprintf( stderr, "ERROR: failed to create base directory '%s' for host '%s': %s\n",
+ full_path, host[i], strerror( errno ) );
+ cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 );
+ exit( EXIT_FAILURE );
+ }
}
while( !all_eof ) {
@@ -999,9 +1017,8 @@ int main( int argc, char *argv[] )
rc = ssh_scp_pull_request( scp[i] );
switch( rc ) {
case SSH_SCP_REQUEST_NEWDIR: {
- // TODO: mkdir in host[i] workspace
-
char *dir = top_dir_stack( &dir_stack[i] );
+
rc = chdir( dir );
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed to change to directory '%s': %s\n",
@@ -1021,7 +1038,7 @@ int main( int argc, char *argv[] )
cleanup_sessions( &session, NULL, &scp, &read_state, &buf, &dir_stack, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
- // TODO: change dir to workspace of scp[i]
+
rc = mkdir( filename, mode );
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed to create directory '%s': %s\n",
@@ -1046,6 +1063,7 @@ int main( int argc, char *argv[] )
exit( EXIT_FAILURE );
}
snprintf( full_path, len, "%s/%s", pwd, filename );
+
rc = push_dir_stack( &dir_stack[i], full_path );
free( pwd );
if( rc < 0 ) {