mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 19:03:07 +02:00
- Fixed bug so that task now recreates (with permission) any missing ~/.taskrc, and recreates any missing ~/.task
This commit is contained in:
parent
ceaba87ba3
commit
06a85c24ad
3 changed files with 37 additions and 45 deletions
|
@ -91,14 +91,15 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \
|
|||
/usr/include/c++/4.0.0/bits/istream.tcc /usr/include/c++/4.0.0/fstream \
|
||||
/usr/include/c++/4.0.0/i686-apple-darwin9/bits/basic_file.h \
|
||||
/usr/include/c++/4.0.0/bits/fstream.tcc /usr/include/c++/4.0.0/sstream \
|
||||
/usr/include/c++/4.0.0/bits/sstream.tcc /usr/include/sys/stat.h task.h \
|
||||
/usr/include/c++/4.0.0/bits/sstream.tcc /usr/include/sys/types.h \
|
||||
/usr/include/sys/stat.h /usr/include/pwd.h task.h \
|
||||
/usr/include/c++/4.0.0/vector /usr/include/c++/4.0.0/bits/stl_vector.h \
|
||||
/usr/include/c++/4.0.0/bits/stl_bvector.h \
|
||||
/usr/include/c++/4.0.0/bits/vector.tcc /usr/include/c++/4.0.0/map \
|
||||
/usr/include/c++/4.0.0/bits/stl_tree.h \
|
||||
/usr/include/c++/4.0.0/bits/stl_map.h \
|
||||
/usr/include/c++/4.0.0/bits/stl_multimap.h /usr/include/sys/types.h \
|
||||
Config.h Table.h color.h Grid.h color.h TDB.h T.h ../auto.h
|
||||
/usr/include/c++/4.0.0/bits/stl_multimap.h Config.h Table.h color.h \
|
||||
Grid.h color.h TDB.h T.h ../auto.h
|
||||
|
||||
/usr/include/c++/4.0.0/iostream:
|
||||
|
||||
|
@ -366,8 +367,12 @@ Config.o Config.o: Config.cpp /usr/include/c++/4.0.0/iostream \
|
|||
|
||||
/usr/include/c++/4.0.0/bits/sstream.tcc:
|
||||
|
||||
/usr/include/sys/types.h:
|
||||
|
||||
/usr/include/sys/stat.h:
|
||||
|
||||
/usr/include/pwd.h:
|
||||
|
||||
task.h:
|
||||
|
||||
/usr/include/c++/4.0.0/vector:
|
||||
|
@ -386,8 +391,6 @@ task.h:
|
|||
|
||||
/usr/include/c++/4.0.0/bits/stl_multimap.h:
|
||||
|
||||
/usr/include/sys/types.h:
|
||||
|
||||
Config.h:
|
||||
|
||||
Table.h:
|
||||
|
|
|
@ -27,8 +27,11 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include "task.h"
|
||||
#include "Config.h"
|
||||
|
||||
|
@ -84,37 +87,33 @@ bool Config::load (const std::string& file)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Config::createDefault (const std::string& file)
|
||||
void Config::createDefault (const std::string& home)
|
||||
{
|
||||
if (confirm (
|
||||
"A configuration file could not be found in "
|
||||
+ file
|
||||
+ "\n\n"
|
||||
+ "Would you like a sample .taskrc created, so task can proceed?"))
|
||||
{
|
||||
// Determine a path to the task directory.
|
||||
std::string taskDir = "";
|
||||
for (int i = file.length () - 1; i >= 0; --i)
|
||||
{
|
||||
if (file[i] == '/')
|
||||
{
|
||||
taskDir = file.substr (0, i) + "/.task";
|
||||
if (-1 == access (taskDir.c_str (), F_OK))
|
||||
mkdir (taskDir.c_str (), S_IRWXU);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Strip trailing slash off home directory, if necessary.
|
||||
std::string terminatedHome = home;
|
||||
if (home[home.length () - 1] == '/')
|
||||
terminatedHome = home.substr (0, home.length () - 1);
|
||||
|
||||
if (taskDir != "")
|
||||
// Determine default names of init file and task directory.
|
||||
std::string rcFile = terminatedHome + "/.taskrc";
|
||||
std::string dataDir = terminatedHome + "/.task";;
|
||||
|
||||
// If rcFile is not found, offer to create one.
|
||||
if (-1 == access (rcFile.c_str (), F_OK))
|
||||
{
|
||||
if (confirm (
|
||||
"A configuration file could not be found in "
|
||||
+ rcFile
|
||||
+ "\n\n"
|
||||
+ "Would you like a sample .taskrc created, so task can proceed?"))
|
||||
{
|
||||
// Create a sample .taskrc file.
|
||||
FILE* out;
|
||||
if ((out = fopen (file.c_str (), "w")))
|
||||
if ((out = fopen (rcFile.c_str (), "w")))
|
||||
{
|
||||
fprintf (out, "data.location=%s\n", taskDir.c_str ());
|
||||
fprintf (out, "data.location=%s\n", dataDir.c_str ());
|
||||
fprintf (out, "command.logging=off\n");
|
||||
fprintf (out, "confirmation=yes\n");
|
||||
fprintf (out, "#nag=Note: try to stick to high priority tasks. See \"task next\".\n");
|
||||
fprintf (out, "next=2\n");
|
||||
fprintf (out, "dateformat=m/d/Y\n");
|
||||
fprintf (out, "showage=yes\n");
|
||||
|
@ -135,24 +134,15 @@ void Config::createDefault (const std::string& file)
|
|||
|
||||
fclose (out);
|
||||
|
||||
// Now set the live values.
|
||||
set ("data.location", taskDir);
|
||||
set ("command.logging", "off");
|
||||
set ("confirmation", "yes");
|
||||
set ("next", 1);
|
||||
set ("dateformat", "m/d/Y");
|
||||
set ("showage", "yes");
|
||||
set ("monthsperline", 3);
|
||||
set ("curses", "on");
|
||||
set ("color", "on");
|
||||
set ("color.overdue", "red");
|
||||
set ("color.active", "cyan");
|
||||
set ("color.tagged", "yellow");
|
||||
|
||||
std::cout << "Done." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->load (rcFile);
|
||||
|
||||
if (-1 == access (dataDir.c_str (), F_OK))
|
||||
mkdir (dataDir.c_str (), S_IRWXU);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -242,10 +242,9 @@ int main (int argc, char** argv)
|
|||
if (!pw)
|
||||
throw std::string ("Could not read home directory from passwd file.");
|
||||
|
||||
// Create a default config file and data directory if necessary.
|
||||
std::string home = pw->pw_dir;
|
||||
home += "/.taskrc";
|
||||
if (!conf.load (home))
|
||||
conf.createDefault (home);
|
||||
conf.createDefault (home);
|
||||
|
||||
TDB tdb;
|
||||
tdb.dataDirectory (conf.get ("data.location"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue