From cc1a81261a35fb3a6bcadba298188e0814eab629 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 24 May 2025 03:38:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 14 +++++------ README.md | 4 +-- dub.json | 2 +- snapd.json => snag.json | 8 +++--- source/app.d | 24 +++++++++--------- source/{snapd => snag}/config/config.d | 30 +++++++++++------------ source/{snapd => snag}/config/exception.d | 4 +-- source/snag/config/package.d | 4 +++ source/{snapd => snag}/core/core.d | 24 +++++++++--------- source/snag/core/package.d | 3 +++ source/snag/package.d | 5 ++++ source/snag/version_.d | 3 +++ source/snapd/config/package.d | 4 --- source/snapd/core/package.d | 3 --- source/snapd/package.d | 5 ---- source/snapd/version_.d | 3 --- 16 files changed, 70 insertions(+), 70 deletions(-) rename snapd.json => snag.json (58%) rename source/{snapd => snag}/config/config.d (80%) rename source/{snapd => snag}/config/exception.d (72%) create mode 100644 source/snag/config/package.d rename source/{snapd => snag}/core/core.d (87%) create mode 100644 source/snag/core/package.d create mode 100644 source/snag/package.d create mode 100644 source/snag/version_.d delete mode 100644 source/snapd/config/package.d delete mode 100644 source/snapd/core/package.d delete mode 100644 source/snapd/package.d delete mode 100644 source/snapd/version_.d diff --git a/.gitignore b/.gitignore index 07c2a16..ccba2bf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,13 @@ docs.json __dummy.html docs/ -/snapd -snapd.so -snapd.dylib -snapd.dll -snapd.a -snapd.lib -snapd-test-* +/snag +snag.so +snag.dylib +snag.dll +snag.a +snag.lib +snag-test-* *.exe *.pdb *.o diff --git a/README.md b/README.md index e91f5bd..868928f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# snapd +# snag -Snapshot D - система резервного копирования на основе фиксации состояния файлов с помощью Git. +Snapshot Git - система резервного копирования на основе фиксации состояния файлов с помощью Git. diff --git a/dub.json b/dub.json index 798e277..f63ef25 100644 --- a/dub.json +++ b/dub.json @@ -5,7 +5,7 @@ "copyright": "Copyright © 2025, Alexander Zhirov", "description": "A backup system based on tracking file states using Git", "license": "GPL-2.0-or-later", - "name": "snapd", + "name": "snag", "targetPath": "bin", "targetType": "executable", "dependencies": { diff --git a/snapd.json b/snag.json similarity index 58% rename from snapd.json rename to snag.json index 3fe8034..f7d3e00 100644 --- a/snapd.json +++ b/snag.json @@ -1,13 +1,13 @@ { "git": "/tmp/testgit", - "project": "/home/alexander/Programming/new/dlang/snapd/source", + "project": "/home/alexander/Programming/new/dlang/snag/source", "email": "user@site.domain", - "user": "snapd", - "presnap": [ + "user": "snag", + "presnag": [ "/usr/bin/ls", "/usr/local/bin/script.sh" ], - "postsnap": [ + "postsnag": [ "/usr/bin/ls", "/usr/local/bin/script.sh" ] diff --git a/source/app.d b/source/app.d index 72df7c3..f3bf551 100644 --- a/source/app.d +++ b/source/app.d @@ -1,14 +1,14 @@ -import snapd; +import snag; import commandr; import std.file; import core.stdc.stdlib : EXIT_SUCCESS, EXIT_FAILURE; -private string programName = "snapd"; +private string programName = "snag"; int main(string[] args) { - auto argumets = new Program(programName, snapdVersion) + auto argumets = new Program(programName, snagVersion) .add(new Command("init", "Initializing the repository for storing snapshots")) .add(new Command("status", "Checking the status of tracked files")) .add(new Command("create", "Create a new backup")) @@ -21,31 +21,31 @@ int main(string[] args) ) .parse(args); - string configFile = argumets.option("config", "snapd.json"); + string configFile = argumets.option("config", "snag.json"); - SnapdConfig config; + SnagConfig config; try { - config = new SnapdConfig(configFile); - } catch (SnapdConfigException e) { + config = new SnagConfig(configFile); + } catch (SnagConfigException e) { e.print(); return EXIT_FAILURE; } - auto snapd = new Snapd(config); + auto snag = new Snag(config); try { argumets .on("init", (init) { - snapd.initialize(); + snag.initialize(); }) .on("status", (status) { - snapd.status(); + snag.status(); }) .on("create", (create) { - snapd.create(); + snag.create(); }); - } catch (SnapdException e) { + } catch (SnagException e) { e.print(); return EXIT_FAILURE; } diff --git a/source/snapd/config/config.d b/source/snag/config/config.d similarity index 80% rename from source/snapd/config/config.d rename to source/snag/config/config.d index e6d7f8f..2d25f51 100644 --- a/source/snapd/config/config.d +++ b/source/snag/config/config.d @@ -1,4 +1,4 @@ -module snapd.config.config; +module snag.config.config; import std.json; import std.file; @@ -6,9 +6,9 @@ import std.path; import std.regex; import std.string; -import snapd.config.exception; +import snag.config.exception; -class SnapdConfig { +class SnagConfig { private string _git; private string _project; private string _email; @@ -27,75 +27,75 @@ class SnapdConfig { jsonText = readText(configFile); jsonData = parseJSON(jsonText); } catch (Exception e) { - throw new SnapdConfigException( + throw new SnagConfigException( "An error occurred while reading the configuration file:\n\t" ~ e.msg ); } if ("git" !in jsonData) - throw new SnapdConfigException( + throw new SnagConfigException( "The configuration file is missing the \"git\" parameter" ); _git = jsonData["git"].str; if (!_git.length) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"git\" parameter must contain the path to the directory" ); if (!_git.isAbsolute) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"git\" parameter must be an absolute path to the directory:\n\t" ~ _git ); if ("project" !in jsonData) - throw new SnapdConfigException( + throw new SnagConfigException( "The configuration file is missing the \"project\" parameter" ); _project = jsonData["project"].str; if (!_project.length) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"project\" parameter must contain the path to the directory" ); if (!_project.isAbsolute) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"project\" parameter must be an absolute path to the directory:\n\t" ~ _project ); if ("email" !in jsonData) - throw new SnapdConfigException( + throw new SnagConfigException( "The configuration file is missing the \"email\" parameter" ); _email = jsonData["email"].str; if (!_email.length) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"email\" parameter must contain an email address" ); if (!isValidEmail(_email)) - throw new SnapdConfigException( + throw new SnagConfigException( "Invalid email address provided in the \"email\" parameter:\n\t" ~ _email ); if ("user" !in jsonData) - throw new SnapdConfigException( + throw new SnagConfigException( "The configuration file is missing the \"user\" parameter" ); _user = jsonData["user"].str; if (!_user.length) - throw new SnapdConfigException( + throw new SnagConfigException( "The \"user\" parameter must contain an user name" ); } diff --git a/source/snapd/config/exception.d b/source/snag/config/exception.d similarity index 72% rename from source/snapd/config/exception.d rename to source/snag/config/exception.d index 1abc0e5..fc21ee1 100644 --- a/source/snapd/config/exception.d +++ b/source/snag/config/exception.d @@ -1,9 +1,9 @@ -module snapd.config.exception; +module snag.config.exception; import std.exception; import std.stdio : writeln; -class SnapdConfigException : Exception { +class SnagConfigException : Exception { this(string msg, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line); } diff --git a/source/snag/config/package.d b/source/snag/config/package.d new file mode 100644 index 0000000..09c7b1d --- /dev/null +++ b/source/snag/config/package.d @@ -0,0 +1,4 @@ +module snag.config; + +public import snag.config.exception; +public import snag.config.config; diff --git a/source/snapd/core/core.d b/source/snag/core/core.d similarity index 87% rename from source/snapd/core/core.d rename to source/snag/core/core.d index 2d285c4..c60d315 100644 --- a/source/snapd/core/core.d +++ b/source/snag/core/core.d @@ -1,6 +1,6 @@ -module snapd.core.core; +module snag.core.core; -import snapd.config; +import snag.config; import std.format; import std.stdio; import std.array; @@ -9,7 +9,7 @@ import std.process; import std.algorithm; import std.string; -class SnapdException : Exception { +class SnagException : Exception { this(string msg, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line); } @@ -19,11 +19,11 @@ class SnapdException : Exception { } } -class Snapd { +class Snag { private string[] _baseCommand; - private SnapdConfig _config; + private SnagConfig _config; - this(SnapdConfig config) { + this(SnagConfig config) { _baseCommand = format( "git --git-dir=%s --work-tree=%s", config.git, config.project @@ -34,7 +34,7 @@ class Snapd { void initialize() { auto result = execute(_baseCommand ~ "init"); if (result.status) - throw new SnapdException( + throw new SnagException( "A Git repository initialization error occurred:\n" ~ result.output ); @@ -43,7 +43,7 @@ class Snapd { _baseCommand ~ ["config", "user.email", _config.email] ); if (result.status) - throw new SnapdException( + throw new SnagException( "A Git repository initialization error occurred:\n" ~ result.output ); @@ -52,7 +52,7 @@ class Snapd { _baseCommand ~ ["config", "user.name", _config.user] ); if (result.status) - throw new SnapdException( + throw new SnagException( "A Git repository initialization error occurred:\n" ~ result.output ); @@ -68,7 +68,7 @@ class Snapd { _baseCommand ~ ["status", "--porcelain"] ); if (result.status) - throw new SnapdException( + throw new SnagException( "An error occurred while checking the file tracking status:\n" ~ result.output ); @@ -90,7 +90,7 @@ class Snapd { _baseCommand ~ ["add", "."] ); if (result.status) - throw new SnapdException( + throw new SnagException( "Failed to prepare files for archiving:\n" ~ result.output ); @@ -99,7 +99,7 @@ class Snapd { _baseCommand ~ ["commit", "-m", "test"] ); if (result.status) - throw new SnapdException( + throw new SnagException( "Failed to create a backup:\n" ~ result.output ); diff --git a/source/snag/core/package.d b/source/snag/core/package.d new file mode 100644 index 0000000..7e8e82a --- /dev/null +++ b/source/snag/core/package.d @@ -0,0 +1,3 @@ +module snag.core; + +public import snag.core.core; diff --git a/source/snag/package.d b/source/snag/package.d new file mode 100644 index 0000000..22b28bf --- /dev/null +++ b/source/snag/package.d @@ -0,0 +1,5 @@ +module snag; + +public import snag.version_; +public import snag.config; +public import snag.core; diff --git a/source/snag/version_.d b/source/snag/version_.d new file mode 100644 index 0000000..2465932 --- /dev/null +++ b/source/snag/version_.d @@ -0,0 +1,3 @@ +module snag.version_; + +enum snagVersion = "0.0.4"; diff --git a/source/snapd/config/package.d b/source/snapd/config/package.d deleted file mode 100644 index 5dd2aed..0000000 --- a/source/snapd/config/package.d +++ /dev/null @@ -1,4 +0,0 @@ -module snapd.config; - -public import snapd.config.exception; -public import snapd.config.config; diff --git a/source/snapd/core/package.d b/source/snapd/core/package.d deleted file mode 100644 index ac6ebaf..0000000 --- a/source/snapd/core/package.d +++ /dev/null @@ -1,3 +0,0 @@ -module snapd.core; - -public import snapd.core.core; diff --git a/source/snapd/package.d b/source/snapd/package.d deleted file mode 100644 index 4360689..0000000 --- a/source/snapd/package.d +++ /dev/null @@ -1,5 +0,0 @@ -module snapd; - -public import snapd.version_; -public import snapd.config; -public import snapd.core; diff --git a/source/snapd/version_.d b/source/snapd/version_.d deleted file mode 100644 index bc63b1b..0000000 --- a/source/snapd/version_.d +++ /dev/null @@ -1,3 +0,0 @@ -module snapd.version_; - -enum snapdVersion = "0.0.3";