5 |
|
// $Id$ |
6 |
|
|
7 |
|
#include "Syncify.hpp" |
8 |
+ |
#include "SambaReader.hpp" |
9 |
|
|
10 |
|
#include <menes-api/exename.hpp> |
11 |
|
#include <menes-app/simple.hpp> |
52 |
|
{ |
53 |
|
void authenticate(const char* srv, const char* shr, char* wg, int wglen, char* un, int unlen, char* pw, int pwlen) |
54 |
|
{ |
55 |
< |
static ext::String user("Douglas Thrift"), password(::getpass("Password:")); |
55 |
> |
static ext::Buffer user("Douglas Thrift"), password(::getpass("Password:")); |
56 |
|
|
57 |
< |
::snprintf(un, unlen, "%s", user.NullTerminate()); |
58 |
< |
::snprintf(pw, pwlen, "%s", password.NullTerminate()); |
57 |
> |
_foreach (ext::Buffer, atom, user) |
58 |
> |
un[_index] = *atom; |
59 |
> |
_foreach (ext::Buffer, atom, password) |
60 |
> |
pw[_index] = *atom; |
61 |
> |
|
62 |
> |
un[user.GetSize() < size_t(unlen) ? user.GetSize() : unlen - 1] = '\0'; |
63 |
> |
pw[password.GetSize() < size_t(pwlen) ? password.GetSize() : pwlen - 1] = '\0'; |
64 |
|
} |
65 |
|
} |
66 |
|
|
79 |
|
ext::String Syncify::program(api::GetExecutablePath().GetName()); |
80 |
|
bool Syncify::debug(false); |
81 |
|
|
82 |
< |
void Syncify::syncify(const ext::String& local, const ext::String& remote) |
82 |
> |
void Syncify::syncify(const api::Path& local, const ext::String& remote) |
83 |
|
{ |
84 |
< |
Matcher dots("^\\.{1,2}$"); |
79 |
< |
ext::RedBlackSet<ext::String> directories; |
80 |
< |
int directory(CheckError(::smbc_opendir(remote.NullTerminate()))); |
81 |
< |
|
82 |
< |
for (::smbc_dirent* entity(::smbc_readdir(directory)); entity != NULL; entity = ::smbc_readdir(directory)) switch (entity->smbc_type) |
84 |
> |
try |
85 |
|
{ |
86 |
< |
case SMBC_FILE: |
87 |
< |
if (entity->name == pattern) |
86 |
> |
Matcher dots("^\\.{1,2}$"); |
87 |
> |
ext::RedBlackSet<ext::String> directories; |
88 |
> |
int directory(CheckError(::smbc_opendir(remote.NullTerminate()))); |
89 |
> |
|
90 |
> |
for (::smbc_dirent* entity(::smbc_readdir(directory)); entity != NULL; entity = ::smbc_readdir(directory)) switch (entity->smbc_type) |
91 |
|
{ |
92 |
< |
api::Cout << entity->name << ios::NewLine; |
92 |
> |
case SMBC_FILE: |
93 |
> |
if (entity->name == pattern) |
94 |
> |
{ |
95 |
> |
api::Path path(local.GetChild(entity->name)); |
96 |
> |
|
97 |
> |
if (!path.Exists()) |
98 |
> |
{ |
99 |
> |
SambaReader samba(remote + "/" + entity->name); |
100 |
> |
api::FileWriter file(path.GetPath()); |
101 |
> |
|
102 |
> |
ios::ReadToWrite(samba, file); |
103 |
> |
} |
104 |
> |
} |
105 |
> |
break; |
106 |
> |
case SMBC_DIR: |
107 |
> |
case SMBC_LINK: |
108 |
> |
if (entity->name != dots) |
109 |
> |
directories.Insert(entity->name); |
110 |
|
} |
89 |
– |
break; |
90 |
– |
case SMBC_DIR: |
91 |
– |
case SMBC_LINK: |
92 |
– |
if (entity->name != dots) |
93 |
– |
directories.Insert(entity->name); |
94 |
– |
} |
111 |
|
|
112 |
< |
::smbc_closedir(directory); |
112 |
> |
::smbc_closedir(directory); |
113 |
|
|
114 |
< |
_foreach (const ext::RedBlackSet<ext::String>, directory, directories) |
115 |
< |
syncify(local + "/" + *directory, remote + "/" + *directory); |
114 |
> |
_foreach (const ext::RedBlackSet<ext::String>, directory, directories) |
115 |
> |
syncify(local.GetChild(*directory), remote + "/" + *directory); |
116 |
> |
} |
117 |
> |
catch (const Error& error) |
118 |
> |
{ |
119 |
> |
api::Cerr << error.GetMessage() << remote << ios::NewLine; |
120 |
> |
} |
121 |
|
} |