archive/File: eliminate Close(), make destructor virtual instead
This commit is contained in:
parent
5da455080b
commit
9aec2f019a
@ -22,19 +22,12 @@
|
|||||||
|
|
||||||
class Mutex;
|
class Mutex;
|
||||||
class Cond;
|
class Cond;
|
||||||
struct ArchivePlugin;
|
|
||||||
class ArchiveVisitor;
|
class ArchiveVisitor;
|
||||||
class InputStream;
|
class InputStream;
|
||||||
|
|
||||||
class ArchiveFile {
|
class ArchiveFile {
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Use Close() instead of delete.
|
|
||||||
*/
|
|
||||||
~ArchiveFile() {}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Close() = 0;
|
virtual ~ArchiveFile() noexcept = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit all entries inside this archive.
|
* Visit all entries inside this archive.
|
||||||
|
@ -49,10 +49,6 @@ public:
|
|||||||
name.erase(len - 4);
|
name.erase(len - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Close() override {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Visit(ArchiveVisitor &visitor) override {
|
virtual void Visit(ArchiveVisitor &visitor) override {
|
||||||
visitor.VisitArchiveEntry(name.c_str());
|
visitor.VisitArchiveEntry(name.c_str());
|
||||||
}
|
}
|
||||||
|
@ -72,10 +72,6 @@ public:
|
|||||||
void Visit(char *path, size_t length, size_t capacity,
|
void Visit(char *path, size_t length, size_t capacity,
|
||||||
ArchiveVisitor &visitor);
|
ArchiveVisitor &visitor);
|
||||||
|
|
||||||
virtual void Close() override {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||||
|
|
||||||
InputStream *OpenStream(const char *path,
|
InputStream *OpenStream(const char *path,
|
||||||
|
@ -57,10 +57,6 @@ public:
|
|||||||
ZzipArchiveFile(std::shared_ptr<ZzipDir> &&_dir)
|
ZzipArchiveFile(std::shared_ptr<ZzipDir> &&_dir)
|
||||||
:dir(std::move(_dir)) {}
|
:dir(std::move(_dir)) {}
|
||||||
|
|
||||||
virtual void Close() override {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||||
|
|
||||||
InputStream *OpenStream(const char *path,
|
InputStream *OpenStream(const char *path,
|
||||||
|
@ -177,7 +177,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
|||||||
|
|
||||||
UpdateArchiveVisitor visitor(*this, *file, directory);
|
UpdateArchiveVisitor visitor(*this, *file, directory);
|
||||||
file->Visit(visitor);
|
file->Visit(visitor);
|
||||||
file->Close();
|
delete file;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -63,7 +63,7 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond)
|
|||||||
auto file = archive_file_open(arplug, Path::FromFS(archive));
|
auto file = archive_file_open(arplug, Path::FromFS(archive));
|
||||||
|
|
||||||
AtScopeExit(file) {
|
AtScopeExit(file) {
|
||||||
file->Close();
|
delete file;
|
||||||
};
|
};
|
||||||
|
|
||||||
return InputStreamPtr(file->OpenStream(filename, mutex, cond));
|
return InputStreamPtr(file->OpenStream(filename, mutex, cond));
|
||||||
|
@ -93,7 +93,7 @@ try {
|
|||||||
|
|
||||||
MyArchiveVisitor visitor;
|
MyArchiveVisitor visitor;
|
||||||
file->Visit(visitor);
|
file->Visit(visitor);
|
||||||
file->Close();
|
delete file;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user