Implemented option -mv

This commit is contained in:
2007-10-27 22:41:24 +00:00
parent d51958fcf5
commit 47978aad19
5 changed files with 187 additions and 44 deletions

View File

@ -450,17 +450,22 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
return(ret);
}
if(Sfile_str(path, img_path, 0)<=0)
return(-1);
if(img_path[0]!='/') {
strcpy(path, xorriso->wdi);
ret= Sfile_add_to_path(path, img_path, 0);
if(ret<=0)
goto much_too_long;
} else
if(Sfile_str(path, img_path, 0)<=0)
return(-1);
apt= npt= path;
eff_path[0]= 0;
if(path[0]==0)
return(2);
if(path[0]!='/') {
sprintf(xorriso->info_text,
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
"Internal error: Unresolvable relative addressing in iso_rr_path '%s'",
img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
return(-1);
}
@ -502,6 +507,7 @@ bonked_root:;
}
ret= Sfile_add_to_path(eff_path, apt, 0);
if(ret<=0) {
much_too_long:;
sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
strlen(eff_path)+strlen(apt)+1);
if(!(flag&1))
@ -527,7 +533,8 @@ bonked_root:;
}
/* @return <=0 = error , 1 = added simple node , 2 = added directory */
/** @param flag bit0= mkdir: graft in as empty directory, not as copy from disk
@return <=0 = error , 1 = added simple node , 2 = added directory */
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag)
{
@ -566,31 +573,33 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
path[sizeof(path)-1]= 0;
apt= npt= path;
if(lstat(disk_path, &stbuf) == -1) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,
"Cannot determine attributes of source file '%s'",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
if(S_ISDIR(stbuf.st_mode))
is_dir= 1;
else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,
"Source file '%s' is of non-supported file type", disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else {
l= strlen(img_path);
if(l>0)
if(img_path[l-1]=='/')
l= 0;
if(l==0) {
if(!(flag&1)) {
if(lstat(disk_path, &stbuf) == -1) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,
"Source '%s' is not a directory. Target '%s' would be.",
disk_path, img_path);
"Cannot determine attributes of source file '%s'",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
if(S_ISDIR(stbuf.st_mode))
is_dir= 1;
else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,
"Source file '%s' is of non-supported file type", disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else {
l= strlen(img_path);
if(l>0)
if(img_path[l-1]=='/')
l= 0;
if(l==0) {
sprintf(xorriso->info_text,
"Source '%s' is not a directory. Target '%s' would be.",
disk_path, img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
}
}
@ -633,7 +642,7 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
return(0);
}
dir= (struct iso_tree_node_dir *) node;
} else if(is_dir || !done) {
} else if(is_dir || (flag&1) || !done) {
dir= iso_tree_add_dir(dir, apt);
if(dir==NULL) {
Xorriso_process_msg_queues(xorriso,0);
@ -649,7 +658,10 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
}
if(done) {
attach_source:;
if(is_dir) {
if(flag&1) {
/* directory node was created above */;
} else if(is_dir) {
/* >>> do this by own recursive operation in order to gain
full control with overwriting */;
@ -1375,3 +1387,81 @@ ex:;
}
int Xorriso_rename(struct XorrisO *xorriso,
char origin[], char dest[], int flag)
{
int ret;
char sfe[4*SfileadrL], eff_dest[SfileadrL], dir_adr[SfileadrL], *cpt;
char *leafname;
struct iso_volume *volume;
struct iso_tree_node_dir *origin_dir, *dest_dir;
struct iso_tree_node *node;
/* Check whether destination exists and may be not overwriteable */
ret= Xorriso_normalize_img_path(xorriso, dest, eff_dest, 1);
if(ret<0)
return(ret);
if(ret==2) {
sprintf(xorriso->info_text, "Renaming refuses to unlink directory: %s",
Text_shellsafe(eff_dest, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if (ret==1 && !xorriso->do_overwrite) {
sprintf(xorriso->info_text, "Renaming may not overwite: %s",
Text_shellsafe(eff_dest, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if(ret>0) {
ret= Xorriso_rmi(xorriso, eff_dest, 0);
if(ret<=0)
return(0);
}
/* Ensure existence of destination directory */
strcpy(dir_adr, eff_dest);
cpt= strrchr(dir_adr, '/');
if(cpt==NULL)
cpt= dir_adr+strlen(dir_adr);
*cpt= 0;
ret= Xorriso_graft_in(xorriso, NULL, dir_adr, 1);
if(ret<=0)
return(ret);
/* Move node */
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
dest_dir= (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume,dir_adr);
strcpy(dir_adr, eff_dest);
cpt= strrchr(dir_adr, '/');
if(cpt==NULL)
cpt= dir_adr+strlen(dir_adr);
*cpt= 0;
origin_dir= (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume,dir_adr);
node= iso_tree_volume_path_to_node(volume,origin);
if(dest_dir==NULL || origin_dir==NULL || node==NULL) {
sprintf(xorriso->info_text,
"Internal error on rename: confirmed node turns out as NULL");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
ret= iso_tree_node_take(origin_dir, node);
if(ret==-1) {
sprintf(xorriso->info_text,
"Internal error on rename: failed to take node");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
iso_tree_add_child(dest_dir, node);
leafname= strrchr(eff_dest, '/');
if(leafname==NULL)
leafname= eff_dest;
else
leafname++;
iso_tree_node_set_name(node, leafname);
return(1);
}