Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'ls' and 'rm' for file, even if it doesn't exist in file system #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fixi/command/ls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def execute args
opt :verbose, "Include all information known about each file. By default,
only paths will be listed.".pack
end
index = Fixi::Index.new(args[0])
index = Fixi::Index.new(args[0], false, nil, false)
if opts[:json]
print "["
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fixi/command/rm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def execute args
opt :dry_run, "Don't do anything; just report what would be done"
end
path = File.expand_path(args[0] || ".")
index = Fixi::Index.new(path)
index = Fixi::Index.new(path, false, nil, false)

index.each(args[0]) do |hash|
relpath = hash['relpath']
Expand Down
11 changes: 6 additions & 5 deletions lib/fixi/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
class Fixi::Index
attr_reader :dotpath, :rootpath, :dbversion, :algorithms, :includes, :excludes

def initialize(startpath, create=false, algorithms=nil)
def initialize(startpath, create=false, algorithms=nil, fs_path_must_exist=true)
startpath = File.expand_path(startpath || ".")
unless File.directory?(startpath)
raise "No such file or directory: #{startpath}" unless File.exist?(startpath)
startpath = File.dirname(startpath)
end
if create
raise Errno::ENOTDIR, "'#{startpath}'" unless File.directory?(startpath)
Fixi::digests(algorithms)
@dotpath = File.join(startpath, ".fixi")
raise "Index already exists at #{@dotpath}" if Dir.exist? @dotpath
Expand Down Expand Up @@ -39,6 +36,10 @@ def initialize(startpath, create=false, algorithms=nil)
open(File.join(@dotpath, "includes"), "w") { |f| f.puts ".*" }
open(File.join(@dotpath, "excludes"), "w") { |f| f.puts "^\\.fixi\\/" }
else
raise Errno::ENOENT, "'#{startpath}'" if fs_path_must_exist and !File.exist?(startpath)
unless File.directory?(startpath)
startpath = File.dirname(startpath)
end
@dotpath = find_dotpath(startpath)
@db = SQLite3::Database.new(File.join(@dotpath, "fixi.db"))
@db.execute("select dbversion, algorithms from fixi") do |row|
Expand Down