]> git.lizzy.rs Git - dragonfireclient.git/blob - src/filesys.cpp
f961dedc685c8ffefff309cfebe4cd30d189444c
[dragonfireclient.git] / src / filesys.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "filesys.h"
21 #include "util/string.h"
22 #include <iostream>
23 #include <cstdio>
24 #include <cstring>
25 #include <cerrno>
26 #include <fstream>
27 #include "log.h"
28 #include "config.h"
29 #include "porting.h"
30 #ifdef __ANDROID__
31 #include "settings.h" // For g_settings
32 #endif
33
34 namespace fs
35 {
36
37 #ifdef _WIN32 // WINDOWS
38
39 #define _WIN32_WINNT 0x0501
40 #include <windows.h>
41 #include <shlwapi.h>
42
43 std::vector<DirListNode> GetDirListing(const std::string &pathstring)
44 {
45         std::vector<DirListNode> listing;
46
47         WIN32_FIND_DATA FindFileData;
48         HANDLE hFind = INVALID_HANDLE_VALUE;
49         DWORD dwError;
50
51         std::string dirSpec = pathstring + "\\*";
52
53         // Find the first file in the directory.
54         hFind = FindFirstFile(dirSpec.c_str(), &FindFileData);
55
56         if (hFind == INVALID_HANDLE_VALUE) {
57                 dwError = GetLastError();
58                 if (dwError != ERROR_FILE_NOT_FOUND && dwError != ERROR_PATH_NOT_FOUND) {
59                         errorstream << "GetDirListing: FindFirstFile error."
60                                         << " Error is " << dwError << std::endl;
61                 }
62         } else {
63                 // NOTE:
64                 // Be very sure to not include '..' in the results, it will
65                 // result in an epic failure when deleting stuff.
66
67                 DirListNode node;
68                 node.name = FindFileData.cFileName;
69                 node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
70                 if (node.name != "." && node.name != "..")
71                         listing.push_back(node);
72
73                 // List all the other files in the directory.
74                 while (FindNextFile(hFind, &FindFileData) != 0) {
75                         DirListNode node;
76                         node.name = FindFileData.cFileName;
77                         node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
78                         if(node.name != "." && node.name != "..")
79                                 listing.push_back(node);
80                 }
81
82                 dwError = GetLastError();
83                 FindClose(hFind);
84                 if (dwError != ERROR_NO_MORE_FILES) {
85                         errorstream << "GetDirListing: FindNextFile error."
86                                         << " Error is " << dwError << std::endl;
87                         listing.clear();
88                         return listing;
89                 }
90         }
91         return listing;
92 }
93
94 bool CreateDir(const std::string &path)
95 {
96         bool r = CreateDirectory(path.c_str(), NULL);
97         if(r == true)
98                 return true;
99         if(GetLastError() == ERROR_ALREADY_EXISTS)
100                 return true;
101         return false;
102 }
103
104 bool PathExists(const std::string &path)
105 {
106         return (GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES);
107 }
108
109 bool IsPathAbsolute(const std::string &path)
110 {
111         return !PathIsRelative(path.c_str());
112 }
113
114 bool IsDir(const std::string &path)
115 {
116         DWORD attr = GetFileAttributes(path.c_str());
117         return (attr != INVALID_FILE_ATTRIBUTES &&
118                         (attr & FILE_ATTRIBUTE_DIRECTORY));
119 }
120
121 bool IsDirDelimiter(char c)
122 {
123         return c == '/' || c == '\\';
124 }
125
126 bool RecursiveDelete(const std::string &path)
127 {
128         infostream<<"Recursively deleting \""<<path<<"\""<<std::endl;
129
130         DWORD attr = GetFileAttributes(path.c_str());
131         bool is_directory = (attr != INVALID_FILE_ATTRIBUTES &&
132                         (attr & FILE_ATTRIBUTE_DIRECTORY));
133         if(!is_directory)
134         {
135                 infostream<<"RecursiveDelete: Deleting file "<<path<<std::endl;
136                 //bool did = DeleteFile(path.c_str());
137                 bool did = true;
138                 if(!did){
139                         errorstream<<"RecursiveDelete: Failed to delete file "
140                                         <<path<<std::endl;
141                         return false;
142                 }
143         }
144         else
145         {
146                 infostream<<"RecursiveDelete: Deleting content of directory "
147                                 <<path<<std::endl;
148                 std::vector<DirListNode> content = GetDirListing(path);
149                 for(size_t i=0; i<content.size(); i++){
150                         const DirListNode &n = content[i];
151                         std::string fullpath = path + DIR_DELIM + n.name;
152                         bool did = RecursiveDelete(fullpath);
153                         if(!did){
154                                 errorstream<<"RecursiveDelete: Failed to recurse to "
155                                                 <<fullpath<<std::endl;
156                                 return false;
157                         }
158                 }
159                 infostream<<"RecursiveDelete: Deleting directory "<<path<<std::endl;
160                 //bool did = RemoveDirectory(path.c_str();
161                 bool did = true;
162                 if(!did){
163                         errorstream<<"Failed to recursively delete directory "
164                                         <<path<<std::endl;
165                         return false;
166                 }
167         }
168         return true;
169 }
170
171 bool DeleteSingleFileOrEmptyDirectory(const std::string &path)
172 {
173         DWORD attr = GetFileAttributes(path.c_str());
174         bool is_directory = (attr != INVALID_FILE_ATTRIBUTES &&
175                         (attr & FILE_ATTRIBUTE_DIRECTORY));
176         if(!is_directory)
177         {
178                 bool did = DeleteFile(path.c_str());
179                 return did;
180         }
181         else
182         {
183                 bool did = RemoveDirectory(path.c_str());
184                 return did;
185         }
186 }
187
188 std::string TempPath()
189 {
190         DWORD bufsize = GetTempPath(0, NULL);
191         if(bufsize == 0){
192                 errorstream<<"GetTempPath failed, error = "<<GetLastError()<<std::endl;
193                 return "";
194         }
195         std::vector<char> buf(bufsize);
196         DWORD len = GetTempPath(bufsize, &buf[0]);
197         if(len == 0 || len > bufsize){
198                 errorstream<<"GetTempPath failed, error = "<<GetLastError()<<std::endl;
199                 return "";
200         }
201         return std::string(buf.begin(), buf.begin() + len);
202 }
203
204 #else // POSIX
205
206 #include <sys/types.h>
207 #include <dirent.h>
208 #include <sys/stat.h>
209 #include <sys/wait.h>
210 #include <unistd.h>
211
212 std::vector<DirListNode> GetDirListing(const std::string &pathstring)
213 {
214         std::vector<DirListNode> listing;
215
216         DIR *dp;
217         struct dirent *dirp;
218         if((dp = opendir(pathstring.c_str())) == NULL) {
219                 //infostream<<"Error("<<errno<<") opening "<<pathstring<<std::endl;
220                 return listing;
221         }
222
223         while ((dirp = readdir(dp)) != NULL) {
224                 // NOTE:
225                 // Be very sure to not include '..' in the results, it will
226                 // result in an epic failure when deleting stuff.
227                 if(strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
228                         continue;
229
230                 DirListNode node;
231                 node.name = dirp->d_name;
232
233                 int isdir = -1; // -1 means unknown
234
235                 /*
236                         POSIX doesn't define d_type member of struct dirent and
237                         certain filesystems on glibc/Linux will only return
238                         DT_UNKNOWN for the d_type member.
239
240                         Also we don't know whether symlinks are directories or not.
241                 */
242 #ifdef _DIRENT_HAVE_D_TYPE
243                 if(dirp->d_type != DT_UNKNOWN && dirp->d_type != DT_LNK)
244                         isdir = (dirp->d_type == DT_DIR);
245 #endif /* _DIRENT_HAVE_D_TYPE */
246
247                 /*
248                         Was d_type DT_UNKNOWN, DT_LNK or nonexistent?
249                         If so, try stat().
250                 */
251                 if(isdir == -1) {
252                         struct stat statbuf{};
253                         if (stat((pathstring + "/" + node.name).c_str(), &statbuf))
254                                 continue;
255                         isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
256                 }
257                 node.dir = isdir;
258                 listing.push_back(node);
259         }
260         closedir(dp);
261
262         return listing;
263 }
264
265 bool CreateDir(const std::string &path)
266 {
267         int r = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
268         if (r == 0) {
269                 return true;
270         }
271
272         // If already exists, return true
273         if (errno == EEXIST)
274                 return true;
275         return false;
276
277 }
278
279 bool PathExists(const std::string &path)
280 {
281         struct stat st{};
282         return (stat(path.c_str(),&st) == 0);
283 }
284
285 bool IsPathAbsolute(const std::string &path)
286 {
287         return path[0] == '/';
288 }
289
290 bool IsDir(const std::string &path)
291 {
292         struct stat statbuf{};
293         if(stat(path.c_str(), &statbuf))
294                 return false; // Actually error; but certainly not a directory
295         return ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
296 }
297
298 bool IsDirDelimiter(char c)
299 {
300         return c == '/';
301 }
302
303 bool RecursiveDelete(const std::string &path)
304 {
305         /*
306                 Execute the 'rm' command directly, by fork() and execve()
307         */
308
309         infostream<<"Removing \""<<path<<"\""<<std::endl;
310
311         //return false;
312
313         pid_t child_pid = fork();
314
315         if(child_pid == 0)
316         {
317                 // Child
318                 char argv_data[3][10000];
319                 strcpy(argv_data[0], "/bin/rm");
320                 strcpy(argv_data[1], "-rf");
321                 strncpy(argv_data[2], path.c_str(), 10000);
322                 char *argv[4];
323                 argv[0] = argv_data[0];
324                 argv[1] = argv_data[1];
325                 argv[2] = argv_data[2];
326                 argv[3] = NULL;
327
328                 verbosestream<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
329                                 <<argv[2]<<"'"<<std::endl;
330
331                 execv(argv[0], argv);
332
333                 // Execv shouldn't return. Failed.
334                 _exit(1);
335         }
336         else
337         {
338                 // Parent
339                 int child_status;
340                 pid_t tpid;
341                 do{
342                         tpid = wait(&child_status);
343                         //if(tpid != child_pid) process_terminated(tpid);
344                 }while(tpid != child_pid);
345                 return (child_status == 0);
346         }
347 }
348
349 bool DeleteSingleFileOrEmptyDirectory(const std::string &path)
350 {
351         if (IsDir(path)) {
352                 bool did = (rmdir(path.c_str()) == 0);
353                 if (!did)
354                         errorstream << "rmdir errno: " << errno << ": " << strerror(errno)
355                                         << std::endl;
356                 return did;
357         }
358
359         bool did = (unlink(path.c_str()) == 0);
360         if (!did)
361                 errorstream << "unlink errno: " << errno << ": " << strerror(errno)
362                                 << std::endl;
363         return did;
364 }
365
366 std::string TempPath()
367 {
368         /*
369                 Should the environment variables TMPDIR, TMP and TEMP
370                 and the macro P_tmpdir (if defined by stdio.h) be checked
371                 before falling back on /tmp?
372
373                 Probably not, because this function is intended to be
374                 compatible with lua's os.tmpname which under the default
375                 configuration hardcodes mkstemp("/tmp/lua_XXXXXX").
376         */
377 #ifdef __ANDROID__
378         return g_settings->get("TMPFolder");
379 #else
380         return DIR_DELIM "tmp";
381 #endif
382 }
383
384 #endif
385
386 void GetRecursiveDirs(std::vector<std::string> &dirs, const std::string &dir)
387 {
388         static const std::set<char> chars_to_ignore = { '_', '.' };
389         if (dir.empty() || !IsDir(dir))
390                 return;
391         dirs.push_back(dir);
392         fs::GetRecursiveSubPaths(dir, dirs, false, chars_to_ignore);
393 }
394
395 std::vector<std::string> GetRecursiveDirs(const std::string &dir)
396 {
397         std::vector<std::string> result;
398         GetRecursiveDirs(result, dir);
399         return result;
400 }
401
402 void GetRecursiveSubPaths(const std::string &path,
403                   std::vector<std::string> &dst,
404                   bool list_files,
405                   const std::set<char> &ignore)
406 {
407         std::vector<DirListNode> content = GetDirListing(path);
408         for (const auto &n : content) {
409                 std::string fullpath = path + DIR_DELIM + n.name;
410                 if (ignore.count(n.name[0]))
411                         continue;
412                 if (list_files || n.dir)
413                         dst.push_back(fullpath);
414                 if (n.dir)
415                         GetRecursiveSubPaths(fullpath, dst, list_files, ignore);
416         }
417 }
418
419 bool DeletePaths(const std::vector<std::string> &paths)
420 {
421         bool success = true;
422         // Go backwards to succesfully delete the output of GetRecursiveSubPaths
423         for(int i=paths.size()-1; i>=0; i--){
424                 const std::string &path = paths[i];
425                 bool did = DeleteSingleFileOrEmptyDirectory(path);
426                 if(!did){
427                         errorstream<<"Failed to delete "<<path<<std::endl;
428                         success = false;
429                 }
430         }
431         return success;
432 }
433
434 bool RecursiveDeleteContent(const std::string &path)
435 {
436         infostream<<"Removing content of \""<<path<<"\""<<std::endl;
437         std::vector<DirListNode> list = GetDirListing(path);
438         for (const DirListNode &dln : list) {
439                 if(trim(dln.name) == "." || trim(dln.name) == "..")
440                         continue;
441                 std::string childpath = path + DIR_DELIM + dln.name;
442                 bool r = RecursiveDelete(childpath);
443                 if(!r) {
444                         errorstream << "Removing \"" << childpath << "\" failed" << std::endl;
445                         return false;
446                 }
447         }
448         return true;
449 }
450
451 bool CreateAllDirs(const std::string &path)
452 {
453
454         std::vector<std::string> tocreate;
455         std::string basepath = path;
456         while(!PathExists(basepath))
457         {
458                 tocreate.push_back(basepath);
459                 basepath = RemoveLastPathComponent(basepath);
460                 if(basepath.empty())
461                         break;
462         }
463         for(int i=tocreate.size()-1;i>=0;i--)
464                 if(!CreateDir(tocreate[i]))
465                         return false;
466         return true;
467 }
468
469 bool CopyFileContents(const std::string &source, const std::string &target)
470 {
471         FILE *sourcefile = fopen(source.c_str(), "rb");
472         if(sourcefile == NULL){
473                 errorstream<<source<<": can't open for reading: "
474                         <<strerror(errno)<<std::endl;
475                 return false;
476         }
477
478         FILE *targetfile = fopen(target.c_str(), "wb");
479         if(targetfile == NULL){
480                 errorstream<<target<<": can't open for writing: "
481                         <<strerror(errno)<<std::endl;
482                 fclose(sourcefile);
483                 return false;
484         }
485
486         size_t total = 0;
487         bool retval = true;
488         bool done = false;
489         char readbuffer[BUFSIZ];
490         while(!done){
491                 size_t readbytes = fread(readbuffer, 1,
492                                 sizeof(readbuffer), sourcefile);
493                 total += readbytes;
494                 if(ferror(sourcefile)){
495                         errorstream<<source<<": IO error: "
496                                 <<strerror(errno)<<std::endl;
497                         retval = false;
498                         done = true;
499                 }
500                 if(readbytes > 0){
501                         fwrite(readbuffer, 1, readbytes, targetfile);
502                 }
503                 if(feof(sourcefile) || ferror(sourcefile)){
504                         // flush destination file to catch write errors
505                         // (e.g. disk full)
506                         fflush(targetfile);
507                         done = true;
508                 }
509                 if(ferror(targetfile)){
510                         errorstream<<target<<": IO error: "
511                                         <<strerror(errno)<<std::endl;
512                         retval = false;
513                         done = true;
514                 }
515         }
516         infostream<<"copied "<<total<<" bytes from "
517                 <<source<<" to "<<target<<std::endl;
518         fclose(sourcefile);
519         fclose(targetfile);
520         return retval;
521 }
522
523 bool CopyDir(const std::string &source, const std::string &target)
524 {
525         if(PathExists(source)){
526                 if(!PathExists(target)){
527                         fs::CreateAllDirs(target);
528                 }
529                 bool retval = true;
530                 std::vector<DirListNode> content = fs::GetDirListing(source);
531
532                 for (const auto &dln : content) {
533                         std::string sourcechild = source + DIR_DELIM + dln.name;
534                         std::string targetchild = target + DIR_DELIM + dln.name;
535                         if(dln.dir){
536                                 if(!fs::CopyDir(sourcechild, targetchild)){
537                                         retval = false;
538                                 }
539                         }
540                         else {
541                                 if(!fs::CopyFileContents(sourcechild, targetchild)){
542                                         retval = false;
543                                 }
544                         }
545                 }
546                 return retval;
547         }
548
549         return false;
550 }
551
552 bool PathStartsWith(const std::string &path, const std::string &prefix)
553 {
554         size_t pathsize = path.size();
555         size_t pathpos = 0;
556         size_t prefixsize = prefix.size();
557         size_t prefixpos = 0;
558         for(;;){
559                 bool delim1 = pathpos == pathsize
560                         || IsDirDelimiter(path[pathpos]);
561                 bool delim2 = prefixpos == prefixsize
562                         || IsDirDelimiter(prefix[prefixpos]);
563
564                 if(delim1 != delim2)
565                         return false;
566
567                 if(delim1){
568                         while(pathpos < pathsize &&
569                                         IsDirDelimiter(path[pathpos]))
570                                 ++pathpos;
571                         while(prefixpos < prefixsize &&
572                                         IsDirDelimiter(prefix[prefixpos]))
573                                 ++prefixpos;
574                         if(prefixpos == prefixsize)
575                                 return true;
576                         if(pathpos == pathsize)
577                                 return false;
578                 }
579                 else{
580                         size_t len = 0;
581                         do{
582                                 char pathchar = path[pathpos+len];
583                                 char prefixchar = prefix[prefixpos+len];
584                                 if(FILESYS_CASE_INSENSITIVE){
585                                         pathchar = tolower(pathchar);
586                                         prefixchar = tolower(prefixchar);
587                                 }
588                                 if(pathchar != prefixchar)
589                                         return false;
590                                 ++len;
591                         } while(pathpos+len < pathsize
592                                         && !IsDirDelimiter(path[pathpos+len])
593                                         && prefixpos+len < prefixsize
594                                         && !IsDirDelimiter(
595                                                 prefix[prefixpos+len]));
596                         pathpos += len;
597                         prefixpos += len;
598                 }
599         }
600 }
601
602 std::string RemoveLastPathComponent(const std::string &path,
603                 std::string *removed, int count)
604 {
605         if(removed)
606                 *removed = "";
607
608         size_t remaining = path.size();
609
610         for(int i = 0; i < count; ++i){
611                 // strip a dir delimiter
612                 while(remaining != 0 && IsDirDelimiter(path[remaining-1]))
613                         remaining--;
614                 // strip a path component
615                 size_t component_end = remaining;
616                 while(remaining != 0 && !IsDirDelimiter(path[remaining-1]))
617                         remaining--;
618                 size_t component_start = remaining;
619                 // strip a dir delimiter
620                 while(remaining != 0 && IsDirDelimiter(path[remaining-1]))
621                         remaining--;
622                 if(removed){
623                         std::string component = path.substr(component_start,
624                                         component_end - component_start);
625                         if(i)
626                                 *removed = component + DIR_DELIM + *removed;
627                         else
628                                 *removed = component;
629                 }
630         }
631         return path.substr(0, remaining);
632 }
633
634 std::string RemoveRelativePathComponents(std::string path)
635 {
636         size_t pos = path.size();
637         size_t dotdot_count = 0;
638         while (pos != 0) {
639                 size_t component_with_delim_end = pos;
640                 // skip a dir delimiter
641                 while (pos != 0 && IsDirDelimiter(path[pos-1]))
642                         pos--;
643                 // strip a path component
644                 size_t component_end = pos;
645                 while (pos != 0 && !IsDirDelimiter(path[pos-1]))
646                         pos--;
647                 size_t component_start = pos;
648
649                 std::string component = path.substr(component_start,
650                                 component_end - component_start);
651                 bool remove_this_component = false;
652                 if (component == ".") {
653                         remove_this_component = true;
654                 } else if (component == "..") {
655                         remove_this_component = true;
656                         dotdot_count += 1;
657                 } else if (dotdot_count != 0) {
658                         remove_this_component = true;
659                         dotdot_count -= 1;
660                 }
661
662                 if (remove_this_component) {
663                         while (pos != 0 && IsDirDelimiter(path[pos-1]))
664                                 pos--;
665                         if (component_start == 0) {
666                                 // We need to remove the delemiter too
667                                 path = path.substr(component_with_delim_end, std::string::npos);
668                         } else {
669                                 path = path.substr(0, pos) + DIR_DELIM +
670                                         path.substr(component_with_delim_end, std::string::npos);
671                         }
672                         if (pos > 0)
673                                 pos++;
674                 }
675         }
676
677         if (dotdot_count > 0)
678                 return "";
679
680         // remove trailing dir delimiters
681         pos = path.size();
682         while (pos != 0 && IsDirDelimiter(path[pos-1]))
683                 pos--;
684         return path.substr(0, pos);
685 }
686
687 std::string AbsolutePath(const std::string &path)
688 {
689 #ifdef _WIN32
690         char *abs_path = _fullpath(NULL, path.c_str(), MAX_PATH);
691 #else
692         char *abs_path = realpath(path.c_str(), NULL);
693 #endif
694         if (!abs_path) return "";
695         std::string abs_path_str(abs_path);
696         free(abs_path);
697         return abs_path_str;
698 }
699
700 const char *GetFilenameFromPath(const char *path)
701 {
702         const char *filename = strrchr(path, DIR_DELIM_CHAR);
703         return filename ? filename + 1 : path;
704 }
705
706 bool safeWriteToFile(const std::string &path, const std::string &content)
707 {
708         std::string tmp_file = path + ".~mt";
709
710         // Write to a tmp file
711         std::ofstream os(tmp_file.c_str(), std::ios::binary);
712         if (!os.good())
713                 return false;
714         os << content;
715         os.flush();
716         os.close();
717         if (os.fail()) {
718                 // Remove the temporary file because writing it failed and it's useless.
719                 remove(tmp_file.c_str());
720                 return false;
721         }
722
723         bool rename_success = false;
724
725         // Move the finished temporary file over the real file
726 #ifdef _WIN32
727         // When creating the file, it can cause Windows Search indexer, virus scanners and other apps
728         // to query the file. This can make the move file call below fail.
729         // We retry up to 5 times, with a 1ms sleep between, before we consider the whole operation failed
730         int number_attempts = 0;
731         while (number_attempts < 5) {
732                 rename_success = MoveFileEx(tmp_file.c_str(), path.c_str(),
733                                 MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
734                 if (rename_success)
735                         break;
736                 sleep_ms(1);
737                 ++number_attempts;
738         }
739 #else
740         // On POSIX compliant systems rename() is specified to be able to swap the
741         // file in place of the destination file, making this a truly error-proof
742         // transaction.
743         rename_success = rename(tmp_file.c_str(), path.c_str()) == 0;
744 #endif
745         if (!rename_success) {
746                 warningstream << "Failed to write to file: " << path.c_str() << std::endl;
747                 // Remove the temporary file because moving it over the target file
748                 // failed.
749                 remove(tmp_file.c_str());
750                 return false;
751         }
752
753         return true;
754 }
755
756 bool Rename(const std::string &from, const std::string &to)
757 {
758         return rename(from.c_str(), to.c_str()) == 0;
759 }
760
761 } // namespace fs
762