Home > OS >  Linux rename and how the mv command "recursive" name
Linux rename and how the mv command "recursive" name

Time:09-30

Rename and mv commands without recursive option, then it is how to realize the folder name? (or, Linux is how to manage directory?)


I now use the fuse in a file system, a directory of a layer of pretending to be a multilayer, and use the map management (such as a new dir11 under dir1-name, is a key for the new/dir1-name/dir11 map), (I think I know the Linux file name should be don't need a recursion, but when I mkdir it gave me the incoming is an absolute path, I directly to do with the absolute path of the map)

But I use the mv, rename command, the system will only call a rename function, even if I achieved all the key name within the rename, the system still does not recognize (think only changed a folder name)

Rename: from [/dir1-name] to [/dir6] flags [0], this is to rename the incoming parameters, that is to say system simply calls a dir1-name to dir6 name, under which the catalog hasn't changed (under directory or begin with dir1-name)


This is a function of I used to name
 
Bool rename (const STD: : string & amp; The from, const STD: : string & amp; To) {
STD: : mapIf (it==map_. End ()) {
STD: : mapIf (dit==dir_map_. End ()) {
return false;
} else {
STD: : mapFor (dit=dir_map_. The begin (); Dit!=dir_map_. End (); Dit++) {
STD: : string DTMP=dit - & gt; First;
if(! DTMP. Find (from)) {/* find at 0 "path", means the key is to start with "path" */
DTMP. Erase (0, from the length ());
if(! DTMP. Find ("/") | | DTMP. Empty ()) {
/* find "/" at 0, means not other dir that name start with "path" */
Fprintf (stderr, "[1; 31 m \ \ e [4 m e rename [% s]", dit - & gt; first. The c_str ());
DTMP=to + DTMP;
Fprintf (stderr, "to [% s] \ [m \ n" e, DTMP. C_str ());
Dir_node dn (new dir_node_n (DTMP));
Dir_map_. Insert (STD: : make_pair (DTMP, dn));
Dir_map_. Erase (dit);
}
}
}
return true;
}
} else {
Map_. Insert (STD: : make_pair (to it - & gt; Second));
Map_. Erase (it);
return true;
}
}


CodePudding user response:

I to the understanding is not thorough, comments could not sure

I think that as long as the function of the system calls to read the file information, opendir getattr, readdir (), I told it this file exists, and give him the file to read, but in fact, even if I tell the system the file exists, and has been renamed file folder, system seems to still think this file is associated in the original folder, so in the renamed file can't see it
  • Related